GUI: no more rectangles

when font fails to load
This commit is contained in:
tildearrow 2023-05-03 01:22:54 -05:00
parent c98f21f1e2
commit 05b10bb50a
5 changed files with 26 additions and 7 deletions

View file

@ -94,13 +94,14 @@ static void ImGui_ImplSDLRenderer_SetupRenderState()
SDL_RenderSetClipRect(bd->SDLRenderer, NULL); SDL_RenderSetClipRect(bd->SDLRenderer, NULL);
} }
void ImGui_ImplSDLRenderer_NewFrame() bool ImGui_ImplSDLRenderer_NewFrame()
{ {
ImGui_ImplSDLRenderer_Data* bd = ImGui_ImplSDLRenderer_GetBackendData(); ImGui_ImplSDLRenderer_Data* bd = ImGui_ImplSDLRenderer_GetBackendData();
IM_ASSERT(bd != NULL && "Did you call ImGui_ImplSDLRenderer_Init()?"); IM_ASSERT(bd != NULL && "Did you call ImGui_ImplSDLRenderer_Init()?");
if (!bd->FontTexture) if (!bd->FontTexture)
ImGui_ImplSDLRenderer_CreateDeviceObjects(); return ImGui_ImplSDLRenderer_CreateDeviceObjects();
return true;
} }
void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data) void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data)

View file

@ -21,7 +21,7 @@ struct SDL_Renderer;
IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_Init(SDL_Renderer* renderer); IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_Init(SDL_Renderer* renderer);
IMGUI_IMPL_API void ImGui_ImplSDLRenderer_Shutdown(); IMGUI_IMPL_API void ImGui_ImplSDLRenderer_Shutdown();
IMGUI_IMPL_API void ImGui_ImplSDLRenderer_NewFrame(); IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_NewFrame();
IMGUI_IMPL_API void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data); IMGUI_IMPL_API void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data);
// Called by Init/NewFrame/Shutdown // Called by Init/NewFrame/Shutdown

View file

@ -95,13 +95,15 @@ static void ImGui_ImplSDLRenderer_SetupRenderState()
SDL_RenderSetClipRect(bd->SDLRenderer, NULL); SDL_RenderSetClipRect(bd->SDLRenderer, NULL);
} }
void ImGui_ImplSDLRenderer_NewFrame() bool ImGui_ImplSDLRenderer_NewFrame()
{ {
ImGui_ImplSDLRenderer_Data* bd = ImGui_ImplSDLRenderer_GetBackendData(); ImGui_ImplSDLRenderer_Data* bd = ImGui_ImplSDLRenderer_GetBackendData();
IM_ASSERT(bd != NULL && "Did you call ImGui_ImplSDLRenderer_Init()?"); IM_ASSERT(bd != NULL && "Did you call ImGui_ImplSDLRenderer_Init()?");
if (!bd->FontTexture) if (!bd->FontTexture)
ImGui_ImplSDLRenderer_CreateDeviceObjects(); return ImGui_ImplSDLRenderer_CreateDeviceObjects();
return true;
} }
void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data) void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data)

View file

@ -21,7 +21,7 @@ struct SDL_Renderer;
IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_Init(SDL_Renderer* renderer); IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_Init(SDL_Renderer* renderer);
IMGUI_IMPL_API void ImGui_ImplSDLRenderer_Shutdown(); IMGUI_IMPL_API void ImGui_ImplSDLRenderer_Shutdown();
IMGUI_IMPL_API void ImGui_ImplSDLRenderer_NewFrame(); IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_NewFrame();
IMGUI_IMPL_API void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data); IMGUI_IMPL_API void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data);
// Called by Init/NewFrame/Shutdown // Called by Init/NewFrame/Shutdown

View file

@ -3750,9 +3750,13 @@ bool FurnaceGUI::loop() {
}); });
} }
bool fontsFailed=false;
layoutTimeBegin=SDL_GetPerformanceCounter(); layoutTimeBegin=SDL_GetPerformanceCounter();
ImGui_ImplSDLRenderer_NewFrame(); if (!ImGui_ImplSDLRenderer_NewFrame()) {
fontsFailed=true;
}
ImGui_ImplSDL2_NewFrame(sdlWin); ImGui_ImplSDL2_NewFrame(sdlWin);
ImGui::NewFrame(); ImGui::NewFrame();
@ -5792,6 +5796,18 @@ bool FurnaceGUI::loop() {
willCommit=false; willCommit=false;
} }
if (fontsFailed) {
showError("it appears I couldn't load these fonts. any setting you can check?");
logE("couldn't load fonts");
ImGui::GetIO().Fonts->Clear();
mainFont=ImGui::GetIO().Fonts->AddFontDefault();
patFont=mainFont;
ImGui_ImplSDLRenderer_DestroyFontsTexture();
if (!ImGui::GetIO().Fonts->Build()) {
logE("error again while building font atlas!");
}
}
if (!editOptsVisible) { if (!editOptsVisible) {
latchTarget=0; latchTarget=0;
latchNibble=false; latchNibble=false;