From 54c2a07de50993d8bad92946543179bb6573c95a Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Wed, 10 Sep 2008 01:01:28 +0000 Subject: [PATCH] Moved SysMessage() from the video plugin into the main app, so the GUI and non-GUI executable can handle it in a different way. This fixes a crash in DolphinNoGUI when SysMessage() was called and tried to use a non-initialized wxWidgets. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@489 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/DolphinWX/Src/Main.cpp | 14 ++++++++++++++ Source/Core/DolphinWX/Src/MainNoGUI.cpp | 18 ++++++++++++++++++ Source/PluginSpecs/pluginspecs_video.h | 2 ++ Source/Plugins/Plugin_VideoOGL/Src/GLInit.cpp | 2 +- Source/Plugins/Plugin_VideoOGL/Src/Globals.cpp | 13 ------------- Source/Plugins/Plugin_VideoOGL/Src/Globals.h | 1 - .../Plugin_VideoOGL/Src/OpcodeDecoding.cpp | 4 ++-- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 2 +- .../Plugin_VideoOGL/Src/VertexLoader.cpp | 2 +- 9 files changed, 39 insertions(+), 19 deletions(-) diff --git a/Source/Core/DolphinWX/Src/Main.cpp b/Source/Core/DolphinWX/Src/Main.cpp index 23da10a48e..1fd8c3d8dc 100644 --- a/Source/Core/DolphinWX/Src/Main.cpp +++ b/Source/Core/DolphinWX/Src/Main.cpp @@ -22,6 +22,7 @@ #endif #include "CPUDetect.h" #include "Globals.h" +#include "Host.h" #include "Common.h" #include "IniFile.h" #include "Main.h" @@ -274,3 +275,16 @@ void Host_UpdateStatusBar(const char* _pText) wxPostEvent(main_frame, event); } + +void Host_SysMessage(const char *fmt, ...) +{ + va_list list; + char msg[512]; + + va_start(list, fmt); + vsprintf(msg, fmt, list); + va_end(list); + + if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0; + wxMessageBox(wxString::FromAscii(msg)); +} diff --git a/Source/Core/DolphinWX/Src/MainNoGUI.cpp b/Source/Core/DolphinWX/Src/MainNoGUI.cpp index f8877f341e..9557fe5f0e 100644 --- a/Source/Core/DolphinWX/Src/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/Src/MainNoGUI.cpp @@ -6,6 +6,7 @@ #endif #include "Globals.h" +#include "Host.h" #include "Common.h" #include "ISOFile.h" #include "CPUDetect.h" @@ -59,6 +60,23 @@ void Host_SetWaitCursor(bool enable){} void Host_UpdateStatusBar(const char* _pText){} +void Host_SysMessage(const char *fmt, ...) +{ + va_list list; + char msg[512]; + + va_start(list, fmt); + vsprintf(msg, fmt, list); + va_end(list); + + size_t len = strlen(msg); + if (msg[len - 1] != '\n') { + msg[len - 1] = '\n'; + msg[len] = '\0'; + } + fprintf(stderr, msg); +} + // Include SDL header so it can hijack main(). #include diff --git a/Source/PluginSpecs/pluginspecs_video.h b/Source/PluginSpecs/pluginspecs_video.h index 6a1822f66e..32df4615de 100644 --- a/Source/PluginSpecs/pluginspecs_video.h +++ b/Source/PluginSpecs/pluginspecs_video.h @@ -13,6 +13,7 @@ typedef void (*TSetPEToken)(const unsigned short _token, const int _bSetTokenA typedef void (*TSetPEFinish)(void); typedef unsigned char* (*TGetMemoryPointer)(const unsigned int _iAddress); typedef void (*TVideoLog)(const char* _pMessage, BOOL _bBreak); +typedef void (*TSysMessage)(const char *fmt, ...); typedef void (*TRequestWindowSize)(int _iWidth, int _iHeight, BOOL _bFullscreen); typedef void (*TCopiedToXFB)(void); typedef BOOL (*TPeekMessages)(void); @@ -50,6 +51,7 @@ typedef struct TSetPEFinish pSetPEFinish; TGetMemoryPointer pGetMemoryPointer; TVideoLog pLog; + TSysMessage pSysMessage; TRequestWindowSize pRequestWindowSize; TCopiedToXFB pCopiedToXFB; TPeekMessages pPeekMessages; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLInit.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GLInit.cpp index 910e6f486c..79b8bebad4 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLInit.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLInit.cpp @@ -217,7 +217,7 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight if (g_VideoInitialize.pWindowHandle == NULL) { - SysMessage("failed to create window"); + g_VideoInitialize.pSysMessage("failed to create window"); return false; } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Globals.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Globals.cpp index 3ca0535e0d..16e858e26c 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Globals.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Globals.cpp @@ -252,16 +252,3 @@ void __Log(int type, const char *fmt, ...) WriteConsole(hConsole, Msg, (DWORD)strlen(Msg), &tmp, 0); #endif } - -void SysMessage(const char *fmt, ...) -{ - va_list list; - char msg[512]; - - va_start(list, fmt); - vsprintf(msg, fmt, list); - va_end(list); - - if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0; - wxMessageBox(wxString::FromAscii(msg)); -} diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Globals.h b/Source/Plugins/Plugin_VideoOGL/Src/Globals.h index 7ce3e3b491..df96cec24e 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Globals.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/Globals.h @@ -221,7 +221,6 @@ extern Statistics stats; void DebugLog(const char* _fmt, ...); void __Log(const char *format, ...); void __Log(int type, const char *format, ...); -void SysMessage(const char *fmt, ...); void HandleGLError(); void InitLUTs(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/OpcodeDecoding.cpp b/Source/Plugins/Plugin_VideoOGL/Src/OpcodeDecoding.cpp index 59590109c3..49a8e616c4 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/OpcodeDecoding.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/OpcodeDecoding.cpp @@ -181,10 +181,10 @@ bool FifoCommandRunnable(void) "This means one of the following:\n" "* The emulated GPU got desynced, disabling dual core can help\n" "* Command stream corrupted by some spurious memory bug\n" - "* This really is an unknown opcode (unlikely)\n\n" + "* This really is an unknown opcode (unlikely)\n" "* Some other sort of bug\n\n" "Dolphin will now likely crash or hang. Enjoy.", Cmd); - SysMessage(szTemp); + g_VideoInitialize.pSysMessage(szTemp); g_VideoInitialize.pLog(szTemp, TRUE); } break; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index d681128784..fdfd1cb88e 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -424,7 +424,7 @@ void Renderer::ReinitView(int nNewWidth, int nNewHeight) if (!OpenGL_Create(g_VideoInitialize, nNewWidth, nNewHeight)) {//nNewWidth&~7, nNewHeight&~7) ) { ERROR_LOG("Failed to recreate, reverting to old settings\n"); if (!OpenGL_Create(g_VideoInitialize, oldwidth, oldheight)) { - SysMessage("Failed to revert, exiting...\n"); + g_VideoInitialize.pSysMessage("Failed to revert, exiting...\n"); // TODO - don't takedown the entire emu exit(0); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.cpp index 899bb07b69..d665f25482 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.cpp @@ -392,7 +392,7 @@ void VertexLoader::ProcessFormat() { char temp[256]; sprintf(temp,"%i %i %i", m_VtxDesc.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements); - SysMessage("VertexLoader_Normal::GetFunction returned zero!"); + g_VideoInitialize.pSysMessage("VertexLoader_Normal::GetFunction returned zero!"); } WriteCall(pFunc);