From fe15566d2ca9340ed09cf682f497a4e0d06eb3c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Mon, 23 Mar 2020 23:08:34 +0100 Subject: [PATCH] Only change modes when the lock is being held, see 2333786 (fixes #700) --- src/client/ThumbnailRendererTask.cpp | 1 - src/gui/game/GameView.cpp | 3 +-- src/gui/preview/PreviewView.cpp | 1 - src/simulation/SaveRenderer.cpp | 22 +++++++++------------- src/simulation/SaveRenderer.h | 4 +--- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/client/ThumbnailRendererTask.cpp b/src/client/ThumbnailRendererTask.cpp index dff19472e..f44332863 100644 --- a/src/client/ThumbnailRendererTask.cpp +++ b/src/client/ThumbnailRendererTask.cpp @@ -22,7 +22,6 @@ ThumbnailRendererTask::~ThumbnailRendererTask() bool ThumbnailRendererTask::doWork() { - SaveRenderer::Ref().ResetModes(); thumbnail = std::unique_ptr(SaveRenderer::Ref().Render(Save.get(), Decorations, Fire)); if (thumbnail) { diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index fe1e5417f..7f21f10f7 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -1784,8 +1784,7 @@ void GameView::NotifyPlaceSaveChanged(GameModel * sender) placeSaveOffset = ui::Point(0, 0); if(sender->GetPlaceSave()) { - SaveRenderer::Ref().CopyModes(sender->GetRenderer()); - placeSaveThumb = SaveRenderer::Ref().Render(sender->GetPlaceSave()); + placeSaveThumb = SaveRenderer::Ref().Render(sender->GetPlaceSave(), true, true, sender->GetRenderer()); selectMode = PlaceSave; selectPoint2 = mousePosition; } diff --git a/src/gui/preview/PreviewView.cpp b/src/gui/preview/PreviewView.cpp index 2acfd87ed..2b25152d2 100644 --- a/src/gui/preview/PreviewView.cpp +++ b/src/gui/preview/PreviewView.cpp @@ -460,7 +460,6 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender) if(save->GetGameSave()) { - SaveRenderer::Ref().ResetModes(); savePreview = SaveRenderer::Ref().Render(save->GetGameSave(), false, true); if(savePreview && savePreview->Buffer && !(savePreview->Width == XRES/2 && savePreview->Height == YRES/2)) diff --git a/src/simulation/SaveRenderer.cpp b/src/simulation/SaveRenderer.cpp index c6e7e07b4..211b1ef26 100644 --- a/src/simulation/SaveRenderer.cpp +++ b/src/simulation/SaveRenderer.cpp @@ -33,10 +33,18 @@ SaveRenderer::SaveRenderer(){ #endif } -VideoBuffer * SaveRenderer::Render(GameSave * save, bool decorations, bool fire) +VideoBuffer * SaveRenderer::Render(GameSave * save, bool decorations, bool fire, Renderer *renderModeSource) { std::lock_guard gx(renderMutex); + ren->ResetModes(); + if (renderModeSource) + { + ren->SetRenderMode(renderModeSource->GetRenderMode()); + ren->SetDisplayMode(renderModeSource->GetDisplayMode()); + ren->SetColourMode(renderModeSource->GetColourMode()); + } + int width, height; VideoBuffer * tempThumb = NULL; width = save->blockWidth; @@ -175,15 +183,3 @@ VideoBuffer * SaveRenderer::Render(unsigned char * saveData, int dataSize, bool SaveRenderer::~SaveRenderer() { } - -void SaveRenderer::CopyModes(Renderer *source) -{ - ren->SetRenderMode(source->GetRenderMode()); - ren->SetDisplayMode(source->GetDisplayMode()); - ren->SetColourMode(source->GetColourMode()); -} - -void SaveRenderer::ResetModes() -{ - ren->ResetModes(); -} diff --git a/src/simulation/SaveRenderer.h b/src/simulation/SaveRenderer.h index b5fbc38d5..c1eb08a87 100644 --- a/src/simulation/SaveRenderer.h +++ b/src/simulation/SaveRenderer.h @@ -19,10 +19,8 @@ class SaveRenderer: public Singleton { std::mutex renderMutex; public: SaveRenderer(); - VideoBuffer * Render(GameSave * save, bool decorations = true, bool fire = true); + VideoBuffer * Render(GameSave * save, bool decorations = true, bool fire = true, Renderer *renderModeSource = nullptr); VideoBuffer * Render(unsigned char * saveData, int saveDataSize, bool decorations = true, bool fire = true); - void CopyModes(Renderer *source); - void ResetModes(); virtual ~SaveRenderer(); private: