[Scummvm-git-logs] scummvm master -> 74e7d777a9b2de1ad6d000334197504947b9cb28

sev- sev at scummvm.org
Tue Jul 27 18:50:54 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
74e7d777a9 BACKENDS: Add OSystem::messageBox() and use it for error handling


Commit: 74e7d777a9b2de1ad6d000334197504947b9cb28
    https://github.com/scummvm/scummvm/commit/74e7d777a9b2de1ad6d000334197504947b9cb28
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2021-07-27T20:50:51+02:00

Commit Message:
BACKENDS: Add OSystem::messageBox() and use it for error handling

Changed paths:
    backends/platform/sdl/sdl.cpp
    backends/platform/sdl/sdl.h
    common/system.h
    common/textconsole.cpp
    common/textconsole.h
    engines/director/director.cpp
    engines/engine.cpp


diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index f59dd30d23..386c8a867f 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -608,6 +608,26 @@ bool OSystem_SDL::setTextInClipboard(const Common::U32String &text) {
 	Common::String utf8Text = text.encode();
 	return SDL_SetClipboardText(utf8Text.c_str()) == 0;
 }
+
+void OSystem_SDL::messageBox(LogMessageType::Type type, const char *message) {
+	Uint32 flags = 0;
+
+	switch (type) {
+	case LogMessageType::kError:
+		flags = SDL_MESSAGEBOX_ERROR;
+		break;
+	case LogMessageType::kWarning:
+		flags = SDL_MESSAGEBOX_WARNING;
+		break;
+	case LogMessageType::kInfo:
+	case LogMessageType::kDebug:
+	default:
+		flags = SDL_MESSAGEBOX_INFORMATION;
+		break;
+	}
+
+	SDL_ShowSimpleMessageBox(flags, "ScummVM", message, _window ? _window->getSDLWindow() : nullptr);
+}
 #endif
 
 #if SDL_VERSION_ATLEAST(2, 0, 14)
diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
index fb34014d4c..2a3cca9c2d 100644
--- a/backends/platform/sdl/sdl.h
+++ b/backends/platform/sdl/sdl.h
@@ -73,6 +73,8 @@ public:
 	virtual bool hasTextInClipboard() override;
 	virtual Common::U32String getTextFromClipboard() override;
 	virtual bool setTextInClipboard(const Common::U32String &text) override;
+
+	virtual void messageBox(LogMessageType::Type type, const char *message) override;
 #endif
 
 #if SDL_VERSION_ATLEAST(2, 0, 14)
diff --git a/common/system.h b/common/system.h
index 80df922024..26c6963a44 100644
--- a/common/system.h
+++ b/common/system.h
@@ -1724,6 +1724,14 @@ public:
 	 */
 	virtual void logMessage(LogMessageType::Type type, const char *message) = 0;
 
+	/**
+	 * Display a dialog box containing the given message.
+	 *
+	 * @param type    Type of the message.
+	 * @param message The message itself.
+	 */
+	virtual void messageBox(LogMessageType::Type type, const char *message) {}
+
 	/**
 	 * Open the log file in a way that allows the user to review it,
 	 * and possibly email it (or parts of it) to the ScummVM team,
diff --git a/common/textconsole.cpp b/common/textconsole.cpp
index d533c4b7e4..3fffc4ba07 100644
--- a/common/textconsole.cpp
+++ b/common/textconsole.cpp
@@ -96,8 +96,12 @@ void NORETURN_PRE error(const char *s, ...) {
 	// any OSystem yet.
 
 	// If there is an error handler, invoke it now
+	bool handled = false;
 	if (Common::s_errorHandler)
-		(*Common::s_errorHandler)(buf_output);
+		handled = (*Common::s_errorHandler)(buf_output);
+
+	if (!handled && g_system)
+		g_system->messageBox(LogMessageType::kError, buf_output);
 
 	if (g_system)
 		g_system->fatalError();
diff --git a/common/textconsole.h b/common/textconsole.h
index 8a772a9b74..ebf5d04d2d 100644
--- a/common/textconsole.h
+++ b/common/textconsole.h
@@ -58,7 +58,7 @@ void setErrorOutputFormatter(OutputFormatter f);
  * A typical example would be a function that shows a debug
  * console and displays the given message in it.
  */
-typedef void (*ErrorHandler)(const char *msg);
+typedef bool (*ErrorHandler)(const char *msg);
 
 /**
  * Set a callback that is invoked by error() after the error
diff --git a/engines/director/director.cpp b/engines/director/director.cpp
index 688df233f6..a0c49e867b 100644
--- a/engines/director/director.cpp
+++ b/engines/director/director.cpp
@@ -120,7 +120,7 @@ Archive *DirectorEngine::getMainArchive() const { return _currentWindow->getMain
 Movie *DirectorEngine::getCurrentMovie() const { return _currentWindow->getCurrentMovie(); }
 Common::String DirectorEngine::getCurrentPath() const { return _currentWindow->getCurrentPath(); }
 
-static void buildbotErrorHandler(const char *msg) { }
+static bool buildbotErrorHandler(const char *msg) { return true; }
 
 void DirectorEngine::setCurrentMovie(Movie *movie) {
 	_currentWindow = movie->getWindow();
diff --git a/engines/engine.cpp b/engines/engine.cpp
index f62001f133..4da6431e0c 100644
--- a/engines/engine.cpp
+++ b/engines/engine.cpp
@@ -79,7 +79,9 @@ static void defaultOutputFormatter(char *dst, const char *src, size_t dstSize) {
 	}
 }
 
-static void defaultErrorHandler(const char *msg) {
+static bool defaultErrorHandler(const char *msg) {
+	bool handled = false;
+
 	// Unless this error -originated- within the debugger itself, we
 	// now invoke the debugger, if available / supported.
 	if (g_engine) {
@@ -92,6 +94,7 @@ static void defaultErrorHandler(const char *msg) {
 		if (debugger && !debugger->isActive()) {
 			debugger->attach(msg);
 			debugger->onFrame();
+			handled = true;
 		}
 
 
@@ -100,6 +103,8 @@ static void defaultErrorHandler(const char *msg) {
 #endif
 
 	}
+
+	return handled;
 }
 
 // Chained games manager




More information about the Scummvm-git-logs mailing list