ENGINES: Create a default debugger when needed if none is yet set

This commit is contained in:
Paul Gilbert 2020-02-09 11:06:20 -08:00 committed by Filippos Karapetis
parent 73f17c2ae0
commit 98f9c4f254
3 changed files with 18 additions and 4 deletions

View File

@ -112,7 +112,7 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
_currentKeyDown.ascii = Common::KEYCODE_BACKSPACE; _currentKeyDown.ascii = Common::KEYCODE_BACKSPACE;
} else if (event.kbd.keycode == Common::KEYCODE_d && (_modifierState & Common::KBD_CTRL)) { } 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) { if (debugger) {
debugger->attach(); debugger->attach();
debugger->onFrame(); debugger->onFrame();

View File

@ -86,7 +86,7 @@ static void defaultErrorHandler(const char *msg) {
// Unless this error -originated- within the debugger itself, we // Unless this error -originated- within the debugger itself, we
// now invoke the debugger, if available / supported. // now invoke the debugger, if available / supported.
if (g_engine) { if (g_engine) {
GUI::Debugger *debugger = g_engine->getDebugger(); GUI::Debugger *debugger = g_engine->getOrCreateDebugger();
#if defined(USE_TASKBAR) #if defined(USE_TASKBAR)
g_system->getTaskbarManager()->notifyError(); g_system->getTaskbarManager()->notifyError();
@ -760,6 +760,15 @@ bool Engine::shouldQuit() {
return (eventMan->shouldQuit() || eventMan->shouldRTL()); 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 { EnginePlugin *Engine::getMetaEnginePlugin() const {
return EngineMan.findPlugin(ConfMan.get("engineid")); return EngineMan.findPlugin(ConfMan.get("engineid"));

View File

@ -174,8 +174,7 @@ public:
virtual void errorString(const char *buf_input, char *buf_output, int buf_output_size); 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 * Return the engine's debugger instance, if any.
* invoke the debugger when a severe error is reported.
*/ */
virtual GUI::Debugger *getDebugger() { return _debugger; } virtual GUI::Debugger *getDebugger() { return _debugger; }
@ -188,6 +187,12 @@ public:
_debugger = debugger; _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. * Determine whether the engine supports the specified feature.
*/ */