From f7fb4538de1f73e3d125a9bd81db6093c96016c7 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Tue, 21 Nov 2017 21:08:33 +0100 Subject: [PATCH] RemoteDesktop: Create states for unknown tokens. This allows to recover from reconnects where creation of some tokens may have taken place before the client was fully connected. --- src/apps/remotedesktop/RemoteView.cpp | 15 ++++++++++----- src/apps/remotedesktop/RemoteView.h | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/apps/remotedesktop/RemoteView.cpp b/src/apps/remotedesktop/RemoteView.cpp index 793e31aac8..de964d67af 100644 --- a/src/apps/remotedesktop/RemoteView.cpp +++ b/src/apps/remotedesktop/RemoteView.cpp @@ -363,19 +363,19 @@ RemoteView::_StateCompareByKey(const uint32 *key, const engine_state *state) } -void +engine_state * RemoteView::_CreateState(uint32 token) { int32 index = fStates.BinarySearchIndexByKey(token, &_StateCompareByKey); if (index >= 0) { TRACE_ERROR("state for token %" B_PRIu32 " already in list\n", token); - return; + return NULL; } engine_state *state = new(std::nothrow) engine_state; if (state == NULL) { TRACE_ERROR("failed to allocate engine state\n"); - return; + return NULL; } fOffscreenBitmap->Lock(); @@ -385,7 +385,7 @@ RemoteView::_CreateState(uint32 token) TRACE_ERROR("failed to allocate offscreen view\n"); fOffscreenBitmap->Unlock(); delete state; - return; + return NULL; } fOffscreenBitmap->AddChild(offscreen); @@ -399,6 +399,7 @@ RemoteView::_CreateState(uint32 token) state->sync_drawing = true; fStates.AddItem(state, -index - 1); + return state; } @@ -606,7 +607,11 @@ RemoteView::_DrawThread() engine_state *state = _FindState(token); if (state == NULL) { TRACE_ERROR("didn't find state for token %" B_PRIu32 "\n", token); - continue; + state = _CreateState(token); + if (state == NULL) { + TRACE_ERROR("failed to create state for unknown token\n"); + continue; + } } BView *offscreen = state->view; diff --git a/src/apps/remotedesktop/RemoteView.h b/src/apps/remotedesktop/RemoteView.h index 50a32534c0..04d0d7b2a1 100644 --- a/src/apps/remotedesktop/RemoteView.h +++ b/src/apps/remotedesktop/RemoteView.h @@ -51,7 +51,7 @@ private: static int _StateCompareByKey(const uint32 *key, const engine_state *state); - void _CreateState(uint32 token); + engine_state * _CreateState(uint32 token); void _DeleteState(uint32 token); engine_state * _FindState(uint32 token);