Skip to content

Commit

Permalink
ImGui: avoid non-reentrant call to VideoPresentScreen().
Browse files Browse the repository at this point in the history
The debugger (which calls VideoPresentScreen) is execute in immediate mode from VideoPresentScreen.

Is this a design problem?

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
  • Loading branch information
audetto committed Jan 11, 2022
1 parent 2abca0c commit c70377f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
32 changes: 20 additions & 12 deletions source/frontends/sdl/imgui/sdlimguiframe.cpp
Expand Up @@ -36,6 +36,7 @@ namespace sa2

SDLImGuiFrame::SDLImGuiFrame(const common2::EmulatorOptions & options)
: SDLFrame(options)
, myPresenting(false)
{
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SA2_CONTEXT_FLAGS);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SA2_CONTEXT_PROFILE_MASK);
Expand Down Expand Up @@ -187,18 +188,25 @@ namespace sa2

void SDLImGuiFrame::VideoPresentScreen()
{
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame(myWindow.get());
ImGui::NewFrame();

// "this" is a bit circular
mySettings.show(this);
DrawAppleVideo();

ImGui::Render();
ClearBackground();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
SDL_GL_SwapWindow(myWindow.get());
// this is NOT REENTRANT
// the debugger (executed via mySettings.show(this)) might call it recursively
if (!myPresenting)
{
myPresenting = true;
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();

// "this" is a bit circular
mySettings.show(this);
DrawAppleVideo();

ImGui::Render();
ClearBackground();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
SDL_GL_SwapWindow(myWindow.get());
myPresenting = false;
}
}

void SDLImGuiFrame::ProcessSingleEvent(const SDL_Event & event, bool & quit)
Expand Down
1 change: 1 addition & 0 deletions source/frontends/sdl/imgui/sdlimguiframe.h
Expand Up @@ -41,6 +41,7 @@ namespace sa2
size_t myBorderlessHeight;

int myDeadTopZone; // for mouse position
bool myPresenting; // VideoPresentScreen() is NOT REENTRANT

SDL_GLContext myGLContext;
ImTextureID myTexture;
Expand Down

0 comments on commit c70377f

Please sign in to comment.