From 293d0b2b0e3b996b991b7a667ec31a64d8865450 Mon Sep 17 00:00:00 2001 From: Vircon32 <34624915+vircon32@users.noreply.github.com> Date: Sun, 14 Apr 2024 13:27:34 +0200 Subject: [PATCH] Prevent video context destruction if no GL context is active --- VideoOutput.cpp | 15 +++++++++------ VideoOutput.hpp | 1 + libretro.cpp | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/VideoOutput.cpp b/VideoOutput.cpp index 20f0810..4109192 100644 --- a/VideoOutput.cpp +++ b/VideoOutput.cpp @@ -161,6 +161,7 @@ VideoOutput::VideoOutput() VBOVertexInfo = 0; VBOIndices = 0; ShaderProgramID = 0; + IsInitialized = false; // initialize vertex indices; they are organized // assuming each quad will be given as 4 vertices, @@ -391,6 +392,7 @@ void VideoOutput::InitRendering() ); LOG( "Finished initializing rendering" ); + IsInitialized = true; } // ----------------------------------------------------------------------------- @@ -451,6 +453,10 @@ void VideoOutput::ReleaseTexture( GLuint& OpenGLTextureID ) void VideoOutput::Destroy() { + // prevent calling GL functions with no context active + if( !IsInitialized ) + return; + LOG( "Destroying video context" ); // release all textures @@ -476,13 +482,10 @@ void VideoOutput::Destroy() // delete our shader program LOG( "Deleting shader program" ); + glDeleteProgram( ShaderProgramID ); + ShaderProgramID = 0; - // these checks should not be needed but Lakka seems to crash here - if( glIsProgram( ShaderProgramID ) && glDeleteProgram ) - { - glDeleteProgram( ShaderProgramID ); - ShaderProgramID = 0; - } + IsInitialized = false; } diff --git a/VideoOutput.hpp b/VideoOutput.hpp index 9483e5d..4ed3d90 100644 --- a/VideoOutput.hpp +++ b/VideoOutput.hpp @@ -51,6 +51,7 @@ class VideoOutput GLuint VBOVertexInfo; GLuint VBOIndices; GLuint ShaderProgramID; + bool IsInitialized; // rendering control for quad groups int QueuedQuads; diff --git a/libretro.cpp b/libretro.cpp index 7dbab41..1b2f7ab 100644 --- a/libretro.cpp +++ b/libretro.cpp @@ -216,7 +216,7 @@ void retro_get_system_info( struct retro_system_info *info ) { memset( info, 0, sizeof( *info ) ); info->library_name = "Vircon32"; - info->library_version = "2023.08.24"; + info->library_version = "2024.04.14"; info->need_fullpath = true; // games can be too large to hold in memory info->valid_extensions = "v32|V32"; // target system may be case sensitive }