add server error messages

This commit is contained in:
caszuu
2026-02-27 16:03:18 +01:00
committed by xytovl
parent c44940d004
commit a823df96d3
10 changed files with 126 additions and 37 deletions
+13 -4
View File
@@ -882,10 +882,19 @@ void scenes::lobby::render(const XrFrameState & frame_state)
if (next_scene)
{
if (!next_scene->alive())
next_scene.reset();
else if (next_scene->current_state() == scenes::stream::state::streaming)
application::push_scene(next_scene);
switch (next_scene->current_state())
{
case scenes::stream::state::streaming:
application::push_scene(next_scene);
break;
case scenes::stream::state::shutdown:
current_tab = tab::server_list;
break;
default:
break;
}
}
update_server_list();
+1
View File
@@ -224,6 +224,7 @@ class lobby : public scene_impl<lobby>
void gui_connecting(locked_notifiable<pin_request_data> & request);
void gui_enter_pin(locked_notifiable<pin_request_data> & request);
void gui_connected(XrTime predicted_display_time);
void gui_disconnected();
void gui_server_list();
void gui_new_server();
void gui_settings();
+49 -6
View File
@@ -249,11 +249,7 @@ void scenes::lobby::gui_enter_pin(locked_notifiable<pin_request_data> & pin_requ
void scenes::lobby::gui_connected(XrTime predicted_display_time)
{
if (not next_scene)
{
current_tab = tab::server_list;
return;
}
assert(next_scene);
if (next_scene->apps.draw_gui(*imgui_ctx, _("Disconnect")) == app_launcher::Cancel)
{
@@ -262,6 +258,42 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time)
}
}
void scenes::lobby::gui_disconnected()
{
using constants::style::button_size;
std::string close_button_label = _("Close");
if (!async_error)
{
async_error = next_scene->pop_stream_error();
if (!async_error)
{
next_scene.reset();
ImGui::CloseCurrentPopup();
return;
}
}
ImGui::Dummy({1000, 1});
ImGui::PushFont(nullptr, constants::gui::font_size_large);
if (server_name == "")
CenterTextH(fmt::format(_F("Disconnected")));
else
CenterTextH(fmt::format(_F("Disconnected from {}"), server_name));
ImGui::PopFont();
ImGui::Text("%s", async_error->c_str());
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - button_size.x - ImGui::GetStyle().WindowPadding.x);
if (ImGui::Button(close_button_label.c_str(), button_size))
{
async_error.reset();
}
imgui_ctx->vibrate_on_hover();
}
void scenes::lobby::gui_new_server()
{
using constants::style::button_size;
@@ -496,8 +528,12 @@ void scenes::lobby::gui_server_list()
config.save();
}
// Check if we need to report errors after a disconnect
if (next_scene and next_scene->current_state() == scenes::stream::state::shutdown and not ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopup))
ImGui::OpenPopup("disconnected");
// Check if an automatic connection has started
if ((async_session.valid() || next_scene) and not ImGui::IsPopupOpen("connecting"))
if ((async_session.valid() || next_scene) and not ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopup))
ImGui::OpenPopup("connecting");
const auto & popup_layer = imgui_ctx->layers()[1];
@@ -516,6 +552,13 @@ void scenes::lobby::gui_server_list()
ImGui::EndPopup();
}
ImGui::SetNextWindowPos({popup_layer_center.x, popup_layer_center.y}, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
if (ImGui::BeginPopupModal("disconnected", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize))
{
gui_disconnected();
ImGui::EndPopup();
}
ImGui::SetNextWindowSize({800, 0});
ImGui::SetNextWindowPos({popup_layer_center.x, popup_layer_center.y}, ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f));
if (ImGui::BeginPopupModal("add or edit server", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize))
+17 -5
View File
@@ -562,7 +562,7 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p
if (state_ != state::streaming and not(decoders[0].empty() and decoders[1].empty()))
{
state_ = state::streaming;
set_state(state::streaming);
spdlog::info("Stream scene ready at t={}", instance.now());
}
}
@@ -759,7 +759,7 @@ bool scenes::stream::is_gui_interactable() const
void scenes::stream::render(const XrFrameState & frame_state)
{
if (exiting)
if (state_ == state::shutdown)
application::pop_scene();
display_time_phase = frame_state.predictedDisplayTime % frame_state.predictedDisplayPeriod;
@@ -768,7 +768,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
last_display_time = frame_state.predictedDisplayTime;
std::shared_lock lock(decoder_mutex);
if (not frame_state.shouldRender or (decoders[0].empty() and decoders[1].empty()) or exiting)
if (not frame_state.shouldRender or (decoders[0].empty() and decoders[1].empty()) or state_ == state::shutdown)
{
// TODO: stop/restart video stream
session.begin_frame();
@@ -848,7 +848,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
blit_handle->feedback.blitted = instance.now();
if (blit_handle->feedback.blitted - blit_handle->feedback.received_from_decoder > 1'000'000'000)
state_ = stream::state::stalled;
set_state(state::stalled);
++blit_handle->feedback.times_displayed;
blit_handle->feedback.displayed = frame_state.predictedDisplayTime;
@@ -1136,7 +1136,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
void scenes::stream::exit()
{
exiting = true;
state_ = state::shutdown;
}
void scenes::stream::setup(const to_headset::video_stream_description & description)
@@ -1261,6 +1261,18 @@ scene::meta & scenes::stream::get_meta_scene()
return m;
}
std::optional<std::string> scenes::stream::pop_stream_error()
{
auto queue = stream_error_queue.lock();
if (queue->empty())
return std::nullopt;
auto err = std::make_optional(queue->front());
queue->pop();
return err;
}
void scenes::stream::on_xr_event(const xr::event & event)
{
switch (event.header.type)
+17 -9
View File
@@ -32,6 +32,7 @@
#include "wivrn_packets.h"
#include "xr/space.h"
#include <mutex>
#include <queue>
#include <shared_mutex>
#include <thread>
#include <vulkan/vulkan_core.h>
@@ -45,7 +46,8 @@ public:
{
initializing,
streaming,
stalled
stalled,
shutdown,
};
static const size_t image_buffer_size = 3;
@@ -72,7 +74,6 @@ private:
std::array<std::shared_ptr<wivrn::shard_accumulator::blit_handle>, decoder_count> common_frame(XrTime display_time);
std::unique_ptr<wivrn_session> network_session;
std::atomic<bool> exiting = false;
std::thread network_thread;
thread_safe<to_headset::tracking_control> tracking_control{};
std::array<std::atomic<interaction_profile>, 2> interaction_profiles; // left and right hand
@@ -104,7 +105,16 @@ private:
std::unordered_multimap<device_id, haptics_action> haptics_actions;
std::vector<std::tuple<device_id, XrAction, XrActionType>> input_actions;
state state_ = state::initializing;
std::atomic<state> state_ = state::initializing;
void set_state(state new_state)
{
state prev = state_;
if (prev == state::shutdown)
return;
state_.compare_exchange_strong(prev, new_state);
}
xr::swapchain swapchain;
@@ -136,7 +146,7 @@ private:
struct gui_toast
{
std::string current_toast;
std::string content;
bool is_urgent = false;
};
@@ -150,6 +160,8 @@ private:
thread_safe<std::optional<gui_toast>> gui_toast;
std::atomic<XrTime> gui_status_last_change;
thread_safe<std::queue<std::string>> stream_error_queue;
XrAction plots_toggle_1 = XR_NULL_HANDLE;
XrAction plots_toggle_2 = XR_NULL_HANDLE;
XrAction recenter_left = XR_NULL_HANDLE;
@@ -230,14 +242,10 @@ public:
}
void exit();
bool alive() const
{
return !exiting;
}
void start_application(std::string appid);
static meta & get_meta_scene();
std::optional<std::string> pop_stream_error();
private:
void process_packets();
+1 -1
View File
@@ -739,7 +739,7 @@ void scenes::stream::gui_toasts()
return;
}
ImGui::Text("%s", (*toast)->current_toast.c_str());
ImGui::Text("%s", (*toast)->content.c_str());
}
void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicted_display_period)
+12 -4
View File
@@ -33,7 +33,7 @@ void scenes::stream::process_packets()
#ifdef __ANDROID__
application::instance().setup_jni();
#endif
while (not exiting)
while (state_ != state::shutdown)
{
try
{
@@ -51,13 +51,21 @@ void scenes::stream::operator()(to_headset::server_message && message)
{
switch (message.kind)
{
case to_headset::server_message::kind::stream_toast:
case to_headset::server_message::kind::stream_toast_urgent:
case to_headset::server_message::kind::toast:
case to_headset::server_message::kind::toast_urgent: {
auto toast = gui_toast.lock();
toast->emplace(message.msg, message.kind == to_headset::server_message::kind::stream_toast_urgent);
toast->emplace(message.msg, message.kind == to_headset::server_message::kind::toast_urgent);
gui_status_last_change = instance.now();
break;
}
case to_headset::server_message::kind::error: {
auto queue = stream_error_queue.lock();
queue->emplace(std::move(message.msg));
break;
}
}
}
+1 -1
View File
@@ -341,7 +341,7 @@ void scenes::stream::tracking()
XrDuration frame_duration;
XrTime pattern_begin = instance.now();
while (not exiting)
while (state_ != state::shutdown)
{
try
{
+6 -2
View File
@@ -612,8 +612,12 @@ struct server_message
{
enum class kind : uint8_t
{
stream_toast,
stream_toast_urgent,
// in-stream toasts (not buffered)
toast,
toast_urgent,
// displayed in lobby after disconnect (buffered)
error,
};
kind kind;
+9 -5
View File
@@ -1182,9 +1182,14 @@ void wivrn_session::reconnect(std::stop_token stop)
const auto & info = connection->info();
const auto [warn_conn, refuse_conn] = validate_headset_info(info);
// TODO: add server-side localization
if (refuse_conn)
{
// FIXME: send a message to client and prompt the user to restart the server
send_control(to_headset::server_message{
.kind = to_headset::server_message::kind::error,
.msg = "Headset incompatible with session.",
});
connection->shutdown();
throw std::runtime_error("headset config incompatible with current session");
@@ -1192,13 +1197,12 @@ void wivrn_session::reconnect(std::stop_token stop)
if (warn_conn)
{
U_LOG_W("Session resumed with outdated settings. Restart the server for settings to apply.");
// TODO: add server-side localization
send_control(to_headset::server_message{
.kind = to_headset::server_message::kind::stream_toast_urgent,
.kind = to_headset::server_message::kind::toast_urgent,
.msg = "Stream resumed with outdated settings. Restart the server for settings to apply.",
});
U_LOG_W("Session resumed with outdated settings. Restart the server for settings to apply.");
}
// update headset info