Keep editor alive when game code throws an exception - #138
Open
mblackman wants to merge 1 commit into
Open
Conversation
The editor runs the project in-process, so an uncaught exception from game or Lua code propagated up through the frame loop and crashed the whole editor. Add RunEditorGuarded, which in an editor session catches the exception, logs it to the console, and pauses execution instead of letting it escape; outside editor mode it is a passthrough so the player and headless tooling fail exactly as before. Applied at the seams where game code runs during an editor session: the per-frame Update tick, the input-event dispatches (Lua handlers and UI button callbacks), and the toolbar Play/Stop scene operations, which run during ImGui render outside the Update guard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The editor runs the project in-process (editor mode is the same
Gameinstance withisPaused-gated systems). An uncaught exception from game or Lua code propagated up throughFrameLoop→Game::Run's loop and crashed the whole editor. (The separate Run Player button already isolates crashes via a child process — that path was never affected.)Change
New header-only
RunEditorGuarded(GameConfig&, context, fn)insrc/Engine/EditorExceptionGuard.h:std::exception(and...), logs it viaLogger::Error(surfaces in the editor Console panel), and setsisPaused = true— so the editor stays alive and the throwing tick doesn't re-raise every frame. Fix the script, hit Play again.Applied at the three seams where game code executes during an editor session:
FrameLoop::Update— the per-frame tick (registry_->Update), which runs every system including Lua.FrameLoop::ProcessInput— the key/mouse/wheelEmitEventdispatches (Lua input handlers,UIButtonSystemcallbacks).EditorToolbarPanelPlay/Stop —ReloadScene/StopScene, which run during ImGui render outside the Update guard. A broken scene load on Play was a real editor-crash path; Play now only un-pauses if the reload succeeded.Lua runtime errors inside a script's
updatewere already swallowed byScriptSystem'sprotected_function. This covers the harder failures: C++ exceptions from systems/bindings, and scene loads / input callbacks invoked outside a protected boundary.Verification
cmake --build build/editor-debug— clean.