From 68ee5167eed6db7e965533d84f88b1d56f8bf244 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sat, 27 Jan 2024 13:27:16 -0500 Subject: [PATCH] GUI: work around layout import crash? not very well tested... may mess up layout issue #1629 --- src/gui/gui.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++------- src/gui/gui.h | 2 ++ 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index b93c13753..21e2e5164 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -3426,6 +3426,10 @@ bool FurnaceGUI::detectOutOfBoundsWindow(SDL_Rect& failing) { _x; \ MEASURE_END(_n) +#define IMPORT_CLOSE(x) \ + if (x) pendingLayoutImportReopen.push(&x); \ + x=false; + bool FurnaceGUI::loop() { DECLARE_METRIC(calcChanOsc) DECLARE_METRIC(mobileControls) @@ -4002,7 +4006,59 @@ bool FurnaceGUI::loop() { layoutTimeBegin=SDL_GetPerformanceCounter(); if (pendingLayoutImport!=NULL) { - ImGui::LoadIniSettingsFromMemory((const char*)pendingLayoutImport,pendingLayoutImportLen); + if (pendingLayoutImportStep==0) { + IMPORT_CLOSE(editControlsOpen); + IMPORT_CLOSE(ordersOpen); + IMPORT_CLOSE(insListOpen); + IMPORT_CLOSE(songInfoOpen); + IMPORT_CLOSE(patternOpen); + IMPORT_CLOSE(insEditOpen); + IMPORT_CLOSE(waveListOpen); + IMPORT_CLOSE(waveEditOpen); + IMPORT_CLOSE(sampleListOpen); + IMPORT_CLOSE(sampleEditOpen); + IMPORT_CLOSE(aboutOpen); + IMPORT_CLOSE(settingsOpen); + IMPORT_CLOSE(mixerOpen); + IMPORT_CLOSE(debugOpen); + IMPORT_CLOSE(inspectorOpen); + IMPORT_CLOSE(oscOpen); + IMPORT_CLOSE(volMeterOpen); + IMPORT_CLOSE(statsOpen); + IMPORT_CLOSE(compatFlagsOpen); + IMPORT_CLOSE(pianoOpen); + IMPORT_CLOSE(notesOpen); + IMPORT_CLOSE(channelsOpen); + IMPORT_CLOSE(regViewOpen); + IMPORT_CLOSE(logOpen); + IMPORT_CLOSE(effectListOpen); + IMPORT_CLOSE(chanOscOpen); + IMPORT_CLOSE(subSongsOpen); + IMPORT_CLOSE(findOpen); + IMPORT_CLOSE(spoilerOpen); + IMPORT_CLOSE(patManagerOpen); + IMPORT_CLOSE(sysManagerOpen); + IMPORT_CLOSE(clockOpen); + IMPORT_CLOSE(speedOpen); + IMPORT_CLOSE(groovesOpen); + IMPORT_CLOSE(xyOscOpen); + } else if (pendingLayoutImportStep==1) { + // let the UI settle + } else if (pendingLayoutImportStep==2) { + ImGui::LoadIniSettingsFromMemory((const char*)pendingLayoutImport,pendingLayoutImportLen); + } else if (pendingLayoutImportStep==3) { + // restore open windows + while (!pendingLayoutImportReopen.empty()) { + bool* next=pendingLayoutImportReopen.front(); + *next=true; + pendingLayoutImportReopen.pop(); + } + } else if (pendingLayoutImportStep==4) { + delete[] pendingLayoutImport; + pendingLayoutImport=NULL; + } + pendingLayoutImportStep++; + if (pendingLayoutImport==NULL) pendingLayoutImportStep=0; } if (!rend->newFrame()) { @@ -4011,14 +4067,6 @@ bool FurnaceGUI::loop() { ImGui_ImplSDL2_NewFrame(sdlWin); ImGui::NewFrame(); - if (pendingLayoutImport!=NULL) { - WAKE_UP; - ImGui::Render(); - delete[] pendingLayoutImport; - pendingLayoutImport=NULL; - continue; - } - // one second counter secondTimer+=ImGui::GetIO().DeltaTime; if (secondTimer>=1.0f) secondTimer=fmod(secondTimer,1.0f); @@ -7277,6 +7325,7 @@ FurnaceGUI::FurnaceGUI(): prevInsData(NULL), pendingLayoutImport(NULL), pendingLayoutImportLen(0), + pendingLayoutImportStep(0), curIns(0), curWave(0), curSample(0), diff --git a/src/gui/gui.h b/src/gui/gui.h index fba435170..b9282b990 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -1978,6 +1978,8 @@ class FurnaceGUI { unsigned char* pendingLayoutImport; size_t pendingLayoutImportLen; + int pendingLayoutImportStep; + FixedQueue pendingLayoutImportReopen; int curIns, curWave, curSample, curOctave, curOrder, playOrder, prevIns, oldRow, editStep, exportLoops, soloChan, orderEditMode, orderCursor; int loopOrder, loopRow, loopEnd, isClipping, newSongCategory, latchTarget;