From 98f9c4f254f081202db3fb77e2438785c4cfaa9b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 9 Feb 2020 11:06:20 -0800 Subject: [PATCH] ENGINES: Create a default debugger when needed if none is yet set --- backends/events/default/default-events.cpp | 2 +- engines/engine.cpp | 11 ++++++++++- engines/engine.h | 9 +++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/backends/events/default/default-events.cpp b/backends/events/default/default-events.cpp index a7c03f5dac7..929546e1fa7 100644 --- a/backends/events/default/default-events.cpp +++ b/backends/events/default/default-events.cpp @@ -112,7 +112,7 @@ bool DefaultEventManager::pollEvent(Common::Event &event) { _currentKeyDown.ascii = Common::KEYCODE_BACKSPACE; } else if (event.kbd.keycode == Common::KEYCODE_d && (_modifierState & Common::KBD_CTRL)) { - GUI::Debugger *debugger = g_engine->getDebugger(); + GUI::Debugger *debugger = g_engine->getOrCreateDebugger(); if (debugger) { debugger->attach(); debugger->onFrame(); diff --git a/engines/engine.cpp b/engines/engine.cpp index d6e267fc8b7..ac6a01beb4b 100644 --- a/engines/engine.cpp +++ b/engines/engine.cpp @@ -86,7 +86,7 @@ static void defaultErrorHandler(const char *msg) { // Unless this error -originated- within the debugger itself, we // now invoke the debugger, if available / supported. if (g_engine) { - GUI::Debugger *debugger = g_engine->getDebugger(); + GUI::Debugger *debugger = g_engine->getOrCreateDebugger(); #if defined(USE_TASKBAR) g_system->getTaskbarManager()->notifyError(); @@ -760,6 +760,15 @@ bool Engine::shouldQuit() { return (eventMan->shouldQuit() || eventMan->shouldRTL()); } +GUI::Debugger *Engine::getOrCreateDebugger() { + if (!_debugger) + // Create a bare-bones debugger. This is useful for engines without their own + // debugger when an error occurs + _debugger = new GUI::Debugger(); + + return _debugger; +} + /* EnginePlugin *Engine::getMetaEnginePlugin() const { return EngineMan.findPlugin(ConfMan.get("engineid")); diff --git a/engines/engine.h b/engines/engine.h index 4172d126cca..65a325f74f9 100644 --- a/engines/engine.h +++ b/engines/engine.h @@ -174,8 +174,7 @@ public: virtual void errorString(const char *buf_input, char *buf_output, int buf_output_size); /** - * Return the engine's debugger instance, if any. Used by error() to - * invoke the debugger when a severe error is reported. + * Return the engine's debugger instance, if any. */ virtual GUI::Debugger *getDebugger() { return _debugger; } @@ -188,6 +187,12 @@ public: _debugger = debugger; } + /** + * Return the engine's debugger instance, or create one if none is present. + * Used by error() to invoke the debugger when a severe error is reported. + */ + GUI::Debugger *getOrCreateDebugger(); + /** * Determine whether the engine supports the specified feature. */