GUI: render backend recovery, part 1

This commit is contained in:
tildearrow 2023-07-02 00:09:39 -05:00
parent 87f80cae1d
commit 5fde2e7e30
12 changed files with 195 additions and 98 deletions

View file

@ -3776,6 +3776,79 @@ bool FurnaceGUI::loop() {
});
}
// recover from dead graphics
if (rend->isDead() || killGraphics) {
killGraphics=false;
logW("graphics are dead! restarting...");
if (sampleTex!=NULL) {
rend->destroyTexture(sampleTex);
sampleTex=NULL;
}
if (chanOscGradTex!=NULL) {
rend->destroyTexture(chanOscGradTex);
chanOscGradTex=NULL;
}
for (auto& i: images) {
if (i.second->tex!=NULL) {
rend->destroyTexture(i.second->tex);
i.second->tex=NULL;
}
}
commitState();
rend->quitGUI();
rend->quit();
ImGui_ImplSDL2_Shutdown();
int initAttempts=0;
SDL_Delay(500);
logD("starting render backend...");
while (++initAttempts<=5) {
if (rend->init(sdlWin)) {
break;
}
SDL_Delay(1000);
logV("trying again...");
}
if (initAttempts>5) {
reportError("can't keep going without graphics! Furnace will quit now.");
quit=true;
break;
}
rend->clear(ImVec4(0.0,0.0,0.0,1.0));
rend->present();
logD("preparing user interface...");
rend->initGUI(sdlWin);
logD("building font...");
if (!ImGui::GetIO().Fonts->Build()) {
logE("error while building font atlas!");
showError("error while loading fonts! please check your settings.");
ImGui::GetIO().Fonts->Clear();
mainFont=ImGui::GetIO().Fonts->AddFontDefault();
patFont=mainFont;
if (rend) rend->destroyFontsTexture();
if (!ImGui::GetIO().Fonts->Build()) {
logE("error again while building font atlas!");
}
}
firstFrame=true;
mustClear=2;
initialScreenWipe=1.0f;
continue;
}
bool fontsFailed=false;
layoutTimeBegin=SDL_GetPerformanceCounter();
@ -6319,6 +6392,8 @@ bool FurnaceGUI::init() {
rend->present();
logD("preparing user interface...");
IMGUI_CHECKVERSION();
ImGui::CreateContext();
rend->initGUI(sdlWin);
applyUISettings();
@ -6556,8 +6631,8 @@ bool FurnaceGUI::finish() {
commitState();
rend->quitGUI();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
quitRender();
ImGui::DestroyContext();
SDL_DestroyWindow(sdlWin);
if (vibrator) {
@ -6617,6 +6692,7 @@ FurnaceGUI::FurnaceGUI():
modTableHex(false),
displayEditString(false),
mobileEdit(false),
killGraphics(false),
vgmExportVersion(0x171),
vgmExportTrailingTicks(-1),
drawHalt(10),