Skip to content

Commit a91e23a

Browse files
committed
[fix] fix raw pointer issues when closing connections
1 parent 2b324f6 commit a91e23a

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

src/gui/render.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ void Render::UpdateInteractions() {
893893
mouse_controller_is_started_ = false;
894894
}
895895

896-
if (start_keyboard_capturer_ && foucs_on_stream_window_) {
896+
if (start_keyboard_capturer_ && focus_on_stream_window_) {
897897
if (!keyboard_capturer_is_started_) {
898898
StartKeyboardCapturer();
899899
keyboard_capturer_is_started_ = true;
@@ -2176,7 +2176,7 @@ void Render::ProcessSdlEvent(const SDL_Event& event) {
21762176
case SDL_EVENT_WINDOW_FOCUS_GAINED:
21772177
if (stream_window_ &&
21782178
SDL_GetWindowID(stream_window_) == event.window.windowID) {
2179-
foucs_on_stream_window_ = true;
2179+
focus_on_stream_window_ = true;
21802180
} else if (main_window_ &&
21812181
SDL_GetWindowID(main_window_) == event.window.windowID) {
21822182
foucs_on_main_window_ = true;
@@ -2186,7 +2186,7 @@ void Render::ProcessSdlEvent(const SDL_Event& event) {
21862186
case SDL_EVENT_WINDOW_FOCUS_LOST:
21872187
if (stream_window_ &&
21882188
SDL_GetWindowID(stream_window_) == event.window.windowID) {
2189-
foucs_on_stream_window_ = false;
2189+
focus_on_stream_window_ = false;
21902190
} else if (main_window_ &&
21912191
SDL_GetWindowID(main_window_) == event.window.windowID) {
21922192
foucs_on_main_window_ = false;
@@ -2200,7 +2200,7 @@ void Render::ProcessSdlEvent(const SDL_Event& event) {
22002200
case SDL_EVENT_MOUSE_BUTTON_DOWN:
22012201
case SDL_EVENT_MOUSE_BUTTON_UP:
22022202
case SDL_EVENT_MOUSE_WHEEL:
2203-
if (foucs_on_stream_window_) {
2203+
if (focus_on_stream_window_) {
22042204
ProcessMouseEvent(event);
22052205
}
22062206
break;

src/gui/render.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ class Render {
434434
bool show_cursor_ = false;
435435
bool keyboard_capturer_is_started_ = false;
436436
bool foucs_on_main_window_ = false;
437-
bool foucs_on_stream_window_ = false;
437+
bool focus_on_stream_window_ = false;
438438
bool main_window_minimized_ = false;
439439
uint32_t last_main_minimize_request_tick_ = 0;
440440
uint32_t last_stream_minimize_request_tick_ = 0;

src/gui/windows/stream_window.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ int Render::StreamWindow() {
138138
UpdateRenderRect();
139139

140140
ControlWindow(props);
141-
141+
142142
// Show file transfer window if needed
143143
FileTransferWindow(props);
144144

@@ -151,12 +151,12 @@ int Render::StreamWindow() {
151151
// std::unique_lock unique_lock(client_properties_mutex_);
152152
auto erase_it = client_properties_.find(remote_id_to_erase);
153153
if (erase_it != client_properties_.end()) {
154-
erase_it = client_properties_.erase(erase_it);
155-
if (client_properties_.empty()) {
156-
SDL_Event event;
157-
event.type = SDL_EVENT_QUIT;
158-
SDL_PushEvent(&event);
159-
}
154+
// Ensure we flush pending STREAM_REFRESH_EVENT events and
155+
// clean up peer resources before erasing the entry, otherwise
156+
// SDL events may still hold raw pointers to freed
157+
// SubStreamWindowProperties (including video_frame_mutex_),
158+
// leading to std::system_error when locking.
159+
CloseTab(erase_it);
160160
}
161161
}
162162
// lock.lock();
@@ -236,10 +236,10 @@ int Render::StreamWindow() {
236236
UpdateRenderRect();
237237

238238
ControlWindow(props);
239-
239+
240240
// Show file transfer window if needed
241241
FileTransferWindow(props);
242-
242+
243243
ImGui::End();
244244

245245
if (!props->peer_) {
@@ -251,12 +251,7 @@ int Render::StreamWindow() {
251251
// std::unique_lock unique_lock(client_properties_mutex_);
252252
auto erase_it = client_properties_.find(remote_id_to_erase);
253253
if (erase_it != client_properties_.end()) {
254-
client_properties_.erase(erase_it);
255-
if (client_properties_.empty()) {
256-
SDL_Event event;
257-
event.type = SDL_EVENT_QUIT;
258-
SDL_PushEvent(&event);
259-
}
254+
CloseTab(erase_it);
260255
}
261256
}
262257
// lock.lock();

0 commit comments

Comments
 (0)