From b37f5d6d7696253f833bbc7b1da152ceacca20c6 Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Wed, 29 Sep 2021 07:46:13 +0300 Subject: [PATCH] Fixed ShowMenu option interrupting ImGui::NewFrame. --- SpaceCadetPinball/options.cpp | 5 ++--- SpaceCadetPinball/options.h | 2 +- SpaceCadetPinball/winmain.cpp | 7 ++++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/SpaceCadetPinball/options.cpp b/SpaceCadetPinball/options.cpp index 22f68bd..138a0a2 100644 --- a/SpaceCadetPinball/options.cpp +++ b/SpaceCadetPinball/options.cpp @@ -67,7 +67,6 @@ void options::init() Options.Sounds = 1; Options.Music = 0; - Options.ShowMenu = 1; Options.FullScreen = 0; Options.LeftFlipperKeyDft = SDLK_z; Options.RightFlipperKeyDft = SDLK_SLASH; @@ -91,7 +90,6 @@ void options::init() Options.UniformScaling = true; Options.Sounds = get_int("Sounds", Options.Sounds); Options.Music = get_int("Music", Options.Music); - Options.ShowMenu = get_int("ShowMenu", Options.ShowMenu); Options.FullScreen = get_int("FullScreen", Options.FullScreen); Options.Players = get_int("Players", Options.Players); Options.LeftFlipperKey = get_int("Left Flipper key", Options.LeftFlipperKey); @@ -107,6 +105,7 @@ void options::init() Options.FramesPerSecond = std::min(MaxFps, std::max(MinUps, get_int("Frames Per Second", DefFps))); Options.UpdatesPerSecond = std::min(MaxUps, std::max(MinUps, get_int("Updates Per Second", DefUps))); Options.UpdatesPerSecond = std::max(Options.UpdatesPerSecond, Options.FramesPerSecond); + Options.ShowMenu = get_int("ShowMenu", true); winmain::UpdateFrameRate(); @@ -122,7 +121,6 @@ void options::uninit() { set_int("Sounds", Options.Sounds); set_int("Music", Options.Music); - set_int("ShowMenu", Options.ShowMenu); set_int("FullScreen", Options.FullScreen); set_int("Players", Options.Players); set_int("Left Flipper key", Options.LeftFlipperKey); @@ -137,6 +135,7 @@ void options::uninit() set_int("Linear Filtering", Options.LinearFiltering); set_int("Frames Per Second", Options.FramesPerSecond); set_int("Updates Per Second", Options.UpdatesPerSecond); + set_int("ShowMenu", Options.ShowMenu); } diff --git a/SpaceCadetPinball/options.h b/SpaceCadetPinball/options.h index 0ee6de2..d3fab42 100644 --- a/SpaceCadetPinball/options.h +++ b/SpaceCadetPinball/options.h @@ -33,7 +33,6 @@ struct optionsStruct { int Sounds; int Music; - int ShowMenu; int FullScreen; int Players; int LeftFlipperKey; @@ -53,6 +52,7 @@ struct optionsStruct bool LinearFiltering; int FramesPerSecond; int UpdatesPerSecond; + bool ShowMenu; }; diff --git a/SpaceCadetPinball/winmain.cpp b/SpaceCadetPinball/winmain.cpp index fbf0491..5b8a526 100644 --- a/SpaceCadetPinball/winmain.cpp +++ b/SpaceCadetPinball/winmain.cpp @@ -245,18 +245,19 @@ int winmain::WinMain(LPCSTR lpCmdLine) { UpdateToFrameCounter -= UpdateToFrameRatio; - if (options::Options.ShowMenu) + // Option might be changed in RenderUi, unpairing NewFrame from EndFrame. + auto showMenu = options::Options.ShowMenu; + if (showMenu) { ImGui_ImplSDL2_NewFrame(); ImGui::NewFrame(); - RenderUi(); } SDL_RenderClear(renderer); render::PresentVScreen(); - if (options::Options.ShowMenu) + if (showMenu) { ImGui::Render(); ImGuiSDL::Render(ImGui::GetDrawData());