fix(gui): use imscope context manager for prior session tint in _gui_func
Convert manual push_style_color / pop_style_color in _gui_func to use the imscope context manager so the pop is exception-safe via Python's with statement. Manual push/pop can desync if render_main_interface raises mid-render, causing 'PopStyleColor() too many times!' imGui assertion on subsequent frames. The try/except around render_main_interface was already there but the pop was outside it, so the pop count could exceed the push count when an exception short-circuited the render.
This commit is contained in:
+12
-14
@@ -771,32 +771,30 @@ class App:
|
||||
render_shader_live_editor(self)
|
||||
render_history_window(self)
|
||||
pushed_prior_tint = False
|
||||
|
||||
|
||||
# Render background shader
|
||||
bg = bg_shader.get_bg()
|
||||
ws = imgui.get_io().display_size
|
||||
if bg.enabled:
|
||||
bg.render(ws.x, ws.y)
|
||||
|
||||
|
||||
theme.render_post_fx(ws.x, ws.y, self.ai_status, self.ui_crt_filter)
|
||||
|
||||
|
||||
if self.perf_profiling_enabled: self.perf_monitor.start_component("_gui_func")
|
||||
if self.is_viewing_prior_session:
|
||||
imgui.push_style_color(imgui.Col_.window_bg, vec4(50, 40, 20))
|
||||
pushed_prior_tint = True
|
||||
|
||||
try:
|
||||
render_main_interface(self)
|
||||
if self.is_viewing_prior_session:
|
||||
with imscope.style_color(imgui.Col_.window_bg, vec4(50, 40, 20)):
|
||||
render_main_interface(self)
|
||||
else:
|
||||
render_main_interface(self)
|
||||
except Exception as e:
|
||||
sys.stderr.write(f"ERROR in _gui_func: {e}\n")
|
||||
traceback.print_exc()
|
||||
|
||||
if pushed_prior_tint:
|
||||
imgui.pop_style_color()
|
||||
|
||||
|
||||
self._handle_history_logic()
|
||||
|
||||
if self.perf_profiling_enabled: self.perf_monitor.end_component("_gui_func")
|
||||
|
||||
if self.perf_profiling_enabled:
|
||||
self.perf_monitor.end_component("_gui_func")
|
||||
return
|
||||
|
||||
def _render_window_if_open(self, name: str, render_func: Callable[[], None], flag_condition: bool = True) -> None:
|
||||
|
||||
Reference in New Issue
Block a user