Pause renderer thread when needed in GameModel

This commit is contained in:
Tamás Bálint Misius 2024-09-15 18:25:16 +02:00
parent 12322bb382
commit c842086309
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
2 changed files with 4 additions and 1 deletions

View File

@ -192,6 +192,7 @@ GameModel::~GameModel()
prefs.Set("Decoration.Alpha", (int)colour.Alpha); prefs.Set("Decoration.Alpha", (int)colour.Alpha);
} }
view->PauseRendererThread();
delete sim; delete sim;
delete ren; delete ren;
//if(activeTools) //if(activeTools)
@ -760,6 +761,7 @@ void GameModel::SetSave(std::unique_ptr<SaveInfo> newSave, bool invertIncludePre
auto *saveData = currentSave->GetGameSave(); auto *saveData = currentSave->GetGameSave();
SaveToSimParameters(*saveData); SaveToSimParameters(*saveData);
sim->clear_sim(); sim->clear_sim();
view->PauseRendererThread();
ren->ClearAccumulation(); ren->ClearAccumulation();
sim->Load(saveData, !invertIncludePressure, { 0, 0 }); sim->Load(saveData, !invertIncludePressure, { 0, 0 });
// This save was created before logging existed // This save was created before logging existed
@ -811,6 +813,7 @@ void GameModel::SetSaveFile(std::unique_ptr<SaveFile> newSave, bool invertInclud
auto *saveData = currentFile->GetGameSave(); auto *saveData = currentFile->GetGameSave();
SaveToSimParameters(*saveData); SaveToSimParameters(*saveData);
sim->clear_sim(); sim->clear_sim();
view->PauseRendererThread();
ren->ClearAccumulation(); ren->ClearAccumulation();
sim->Load(saveData, !invertIncludePressure, { 0, 0 }); sim->Load(saveData, !invertIncludePressure, { 0, 0 });
Client::Ref().OverwriteAuthorInfo(saveData->authors); Client::Ref().OverwriteAuthorInfo(saveData->authors);

View File

@ -267,7 +267,7 @@ public:
{ {
return *rendererFrame; return *rendererFrame;
} }
// Call this before accessing Renderer "out of turn", e.g. from RenderView. This *does not* // Call this before accessing Renderer "out of turn", e.g. from RenderView or GameModel. This *does not*
// include OptionsModel or Lua setting functions because they only access the RendererSettings // include OptionsModel or Lua setting functions because they only access the RendererSettings
// in GameModel, or Lua drawing functions because they only access Renderer in eventTraitSimGraphics // in GameModel, or Lua drawing functions because they only access Renderer in eventTraitSimGraphics
// and *SimDraw events, and the renderer thread gets paused anyway if there are handlers // and *SimDraw events, and the renderer thread gets paused anyway if there are handlers