diff --git a/src/Graphics/OpenGLContext/ThreadedOpenGl/opengl_WrappedFunctions.h b/src/Graphics/OpenGLContext/ThreadedOpenGl/opengl_WrappedFunctions.h index 46a46f68..7631a2e1 100644 --- a/src/Graphics/OpenGLContext/ThreadedOpenGl/opengl_WrappedFunctions.h +++ b/src/Graphics/OpenGLContext/ThreadedOpenGl/opengl_WrappedFunctions.h @@ -4820,23 +4820,25 @@ public: { } - static std::shared_ptr get() + static std::shared_ptr get(m64p_error& returnValue) { static int poolId = OpenGlCommandPool::get().getNextAvailablePool(); auto ptr = getFromPool(poolId); - ptr->set(); + ptr->set(returnValue); return ptr; } void commandToExecute() override { - ::CoreVideo_Init(); + *m_returnValue = ::CoreVideo_Init(); } private: - void set() + void set(m64p_error& returnValue) { + m_returnValue = &returnValue; } + m64p_error* m_returnValue; }; class CoreVideoQuitCommand : public OpenGlCommand diff --git a/src/Graphics/OpenGLContext/ThreadedOpenGl/opengl_Wrapper.cpp b/src/Graphics/OpenGLContext/ThreadedOpenGl/opengl_Wrapper.cpp index 162474d5..f583ba70 100644 --- a/src/Graphics/OpenGLContext/ThreadedOpenGl/opengl_Wrapper.cpp +++ b/src/Graphics/OpenGLContext/ThreadedOpenGl/opengl_Wrapper.cpp @@ -1327,12 +1327,14 @@ namespace opengl { #ifdef MUPENPLUSAPI - void FunctionWrapper::CoreVideo_Init() + m64p_error FunctionWrapper::CoreVideo_Init() { + m64p_error returnValue; if (m_threaded_wrapper) - executeCommand(CoreVideoInitCommand::get()); + executeCommand(CoreVideoInitCommand::get(returnValue)); else - CoreVideoInitCommand::get()->performCommandSingleThreaded(); + CoreVideoInitCommand::get(returnValue)->performCommandSingleThreaded(); + return returnValue; } void FunctionWrapper::CoreVideo_Quit() diff --git a/src/Graphics/OpenGLContext/ThreadedOpenGl/opengl_Wrapper.h b/src/Graphics/OpenGLContext/ThreadedOpenGl/opengl_Wrapper.h index fce1722f..efa714ec 100644 --- a/src/Graphics/OpenGLContext/ThreadedOpenGl/opengl_Wrapper.h +++ b/src/Graphics/OpenGLContext/ThreadedOpenGl/opengl_Wrapper.h @@ -179,7 +179,7 @@ namespace opengl { #ifdef MUPENPLUSAPI //Vid_ext functions - static void CoreVideo_Init(); + static m64p_error CoreVideo_Init(); static void CoreVideo_Quit(); static m64p_error CoreVideo_SetVideoMode(int screenWidth, int screenHeight, int bitsPerPixel, m64p_video_mode mode, m64p_video_flags flags); static void CoreVideo_GL_SetAttribute(m64p_GLattr attribute, int value); diff --git a/src/Graphics/OpenGLContext/mupen64plus/mupen64plus_DisplayWindow.cpp b/src/Graphics/OpenGLContext/mupen64plus/mupen64plus_DisplayWindow.cpp index 8a3c98a0..bdcfb628 100644 --- a/src/Graphics/OpenGLContext/mupen64plus/mupen64plus_DisplayWindow.cpp +++ b/src/Graphics/OpenGLContext/mupen64plus/mupen64plus_DisplayWindow.cpp @@ -76,7 +76,13 @@ void DisplayWindowMupen64plus::_setAttributes() bool DisplayWindowMupen64plus::_start() { FunctionWrapper::setThreadedMode(config.video.threadedVideo); - FunctionWrapper::CoreVideo_Init(); + auto returnValue = FunctionWrapper::CoreVideo_Init(); + if (returnValue != M64ERR_SUCCESS) { + LOG(LOG_ERROR, "Error in CoreVideo_Init. Error code: %d", returnValue); + FunctionWrapper::CoreVideo_Quit(); + return false; + } + _setAttributes(); m_bFullscreen = config.video.fullscreen > 0; @@ -87,9 +93,10 @@ bool DisplayWindowMupen64plus::_start() printf("(II) Setting video mode %dx%d...\n", m_screenWidth, m_screenHeight); const m64p_video_flags flags = M64VIDEOFLAG_SUPPORT_RESIZING; - if (FunctionWrapper::CoreVideo_SetVideoMode(m_screenWidth, m_screenHeight, 0, m_bFullscreen ? M64VIDEO_FULLSCREEN : M64VIDEO_WINDOWED, flags) != M64ERR_SUCCESS) { + returnValue = FunctionWrapper::CoreVideo_SetVideoMode(m_screenWidth, m_screenHeight, 0, m_bFullscreen ? M64VIDEO_FULLSCREEN : M64VIDEO_WINDOWED, flags); + if (returnValue != M64ERR_SUCCESS) { //printf("(EE) Error setting videomode %dx%d\n", m_screenWidth, m_screenHeight); - LOG(LOG_ERROR, "Error setting videomode %dx%d", m_screenWidth, m_screenHeight); + LOG(LOG_ERROR, "Error setting videomode %dx%d. Error code: %d", m_screenWidth, m_screenHeight, returnValue); FunctionWrapper::CoreVideo_Quit(); return false; }