Skip to content

Commit cf51884

Browse files
committed
reset soil2 gl when gl resolver is destroyed
1 parent d31aebb commit cf51884

4 files changed

Lines changed: 33 additions & 12 deletions

File tree

src/libprojectM/Renderer/PlatformGLResolver.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace Platform {
2525

2626
GLResolver::~GLResolver()
2727
{
28+
SOIL_GL_Destroy();
29+
2830
// make sure handles are released
2931
m_eglLib.Close();
3032
m_glLib.Close();
@@ -110,6 +112,8 @@ void GLResolver::Shutdown()
110112
{
111113
const std::lock_guard<std::mutex> lock(m_mutex);
112114

115+
SOIL_GL_Destroy();
116+
113117
m_loaded = false;
114118
m_backend = Backend::None;
115119

@@ -145,7 +149,7 @@ auto GLResolver::GetProcAddress(const char* name) const -> GLapiproc
145149

146150
void GLResolver::OpenNativeLibraries()
147151
{
148-
// Best-effort: macOS or minimal EGL setups may fail to open
152+
// Best-effort: mac or minimal EGL setups may fail to open
149153

150154
#ifdef _WIN32
151155
static constexpr std::array<const char*, 3> kEglNames = {"libEGL.dll", "EGL.dll", nullptr};

src/libprojectM/Renderer/PlatformGLResolver.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ enum class Backend : std::uint8_t
3939
WglGl = 3,
4040

4141
/**
42-
* WegGL proc resolver (Emscripten only).
42+
* WegGl proc resolver (Emscripten only).
4343
*/
44-
WebGL = 4,
44+
WebGl = 4,
4545

4646
/**
4747
* User resolver is used, no backend detection.
@@ -61,6 +61,8 @@ using UserResolver = void* (*)(const char* name, void* userData);
6161
* @brief Cross-platform runtime GL/GLES resolver.
6262
*
6363
* This resolver:
64+
* - Supports: EGL, GLES, GLX, WGL, WebGL or a user supplied resolver.
65+
* - Platforms: Android, Emscripten, Linux, Mac, Windows.
6466
* - Must be initialized after a GL/GLES context has been created and made current.
6567
* - Probes for EGL/GLX/WGL by checking for a current context.
6668
* - Uses GLAD2 non-MX entrypoints (gladLoadGL / gladLoadGLES2) via a universal resolver.

vendor/SOIL2/src/SOIL2/SOIL2.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -336,40 +336,54 @@ typedef void (APIENTRY * P_SOIL_GLGENERATEMIPMAPPROC)(GLenum target);
336336
static P_SOIL_GLGENERATEMIPMAPPROC soilGlGenerateMipmap = NULL;
337337

338338

339-
static int soil2_gl_inited = 0;
340-
341-
339+
static int soil2GlInitialized = 0;
342340

343341
void SOIL_GL_Init()
344342
{
345343
/* Must be called after a GL context exists and AFTER SOIL_GL_SetResolver(). */
346-
if (soil2_gl_inited)
344+
if (soil2GlInitialized)
347345
return;
348346

349347
/* Resolve compressed upload */
350348
soilGlCompressedTexImage2D =
351349
(P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC)SOIL_GL_GetProcAddress("glCompressedTexImage2D");
352350
if (!soilGlCompressedTexImage2D)
351+
{
353352
soilGlCompressedTexImage2D =
354353
(P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC)SOIL_GL_GetProcAddress("glCompressedTexImage2DARB");
354+
}
355355

356356
/* Resolve mipmap generator (desktop + ES extensions) */
357357
soilGlGenerateMipmap =
358358
(P_SOIL_GLGENERATEMIPMAPPROC)SOIL_GL_GetProcAddress("glGenerateMipmap");
359359
if (!soilGlGenerateMipmap)
360+
{
360361
soilGlGenerateMipmap =
361362
(P_SOIL_GLGENERATEMIPMAPPROC)SOIL_GL_GetProcAddress("glGenerateMipmapEXT");
363+
}
362364
if (!soilGlGenerateMipmap)
365+
{
363366
soilGlGenerateMipmap =
364367
(P_SOIL_GLGENERATEMIPMAPPROC)SOIL_GL_GetProcAddress("glGenerateMipmapOES");
368+
}
369+
370+
soil2GlInitialized = 1;
371+
}
365372

366-
soil2_gl_inited = 1;
373+
void SOIL_GL_Destroy()
374+
{
375+
soil2GlInitialized = 0;
376+
soilGlCompressedTexImage2D = NULL;
377+
soilGlGenerateMipmap = NULL;
378+
soilGlGenerateMipmap = NULL;
379+
soilGlGenerateMipmap = NULL;
367380
}
368381

382+
369383
/* Ensure OpenGL function pointers are initialized (safe to call repeatedly). */
370-
static void soil2_ensure_gl_inited(void)
384+
static void soil2_ensure_gl_initialized(void)
371385
{
372-
if(!soil2_gl_inited)
386+
if(!soil2GlInitialized)
373387
{
374388
SOIL_GL_Init();
375389
}
@@ -3171,7 +3185,7 @@ static P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC get_glCompressedTexImage2D_addr()
31713185
{
31723186
/* Always go through the user-provided resolver to avoid link-time symbol collisions
31733187
(e.g. when GLAD or other loaders are compiled into the binary). */
3174-
soil2_ensure_gl_inited();
3188+
soil2_ensure_gl_initialized();
31753189
return soilGlCompressedTexImage2D;
31763190
}
31773191

@@ -3368,7 +3382,7 @@ int query_gen_mipmap_capability( void )
33683382
}
33693383
else
33703384
{
3371-
soil2_ensure_gl_inited();
3385+
soil2_ensure_gl_initialized();
33723386

33733387
if (soilGlGenerateMipmap)
33743388
{

vendor/SOIL2/src/SOIL2/SOIL2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extern "C" {
6363

6464
unsigned long SOIL_version();
6565
void SOIL_GL_Init();
66+
void SOIL_GL_Destroy();
6667

6768
/**
6869
The format of images that may be loaded (force_channels).

0 commit comments

Comments
 (0)