mirror of
https://github.com/glfw/glfw.git
synced 2026-02-17 21:12:34 +01:00
Allow NULL argument to _glfwPlatformFreeModule
This matches the behavior of _glfw_free and the public API, simplifying cleanup code.
This commit is contained in:
@@ -688,6 +688,8 @@ void _glfwTerminateCocoa(void)
|
||||
_glfwTerminateEGL();
|
||||
_glfwTerminateOSMesa();
|
||||
|
||||
memset(&_glfw.ns, 0, sizeof(_glfw.ns));
|
||||
|
||||
} // autoreleasepool
|
||||
}
|
||||
|
||||
|
||||
@@ -333,11 +333,8 @@ static void destroyContextEGL(_GLFWwindow* window)
|
||||
if (_glfw.platform.platformID != GLFW_PLATFORM_X11 ||
|
||||
window->context.client != GLFW_OPENGL_API)
|
||||
{
|
||||
if (window->context.egl.client)
|
||||
{
|
||||
_glfwPlatformFreeModule(window->context.egl.client);
|
||||
window->context.egl.client = NULL;
|
||||
}
|
||||
_glfwPlatformFreeModule(window->context.egl.client);
|
||||
window->context.egl.client = NULL;
|
||||
}
|
||||
|
||||
if (window->context.egl.surface)
|
||||
@@ -552,7 +549,7 @@ void _glfwTerminateEGL(void)
|
||||
}
|
||||
|
||||
// Free modules only after all wayland termination functions are called
|
||||
if (_glfw.egl.handle && _glfw.platform.platformID != GLFW_PLATFORM_WAYLAND)
|
||||
if (_glfw.platform.platformID != GLFW_PLATFORM_WAYLAND)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.egl.handle);
|
||||
_glfw.egl.handle = NULL;
|
||||
|
||||
@@ -429,11 +429,8 @@ void _glfwTerminateGLX(void)
|
||||
// NOTE: This function must not call any X11 functions, as it is called
|
||||
// after XCloseDisplay (see _glfwTerminateX11 for details)
|
||||
|
||||
if (_glfw.glx.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.glx.handle);
|
||||
_glfw.glx.handle = NULL;
|
||||
}
|
||||
_glfwPlatformFreeModule(_glfw.glx.handle);
|
||||
_glfw.glx.handle = NULL;
|
||||
}
|
||||
|
||||
#define SET_ATTRIB(a, v) \
|
||||
|
||||
@@ -260,5 +260,6 @@ void _glfwTerminateNull(void)
|
||||
free(_glfw.null.clipboardString);
|
||||
_glfwTerminateOSMesa();
|
||||
_glfwTerminateEGL();
|
||||
memset(&_glfw.null, 0, sizeof(_glfw.null));
|
||||
}
|
||||
|
||||
|
||||
@@ -180,11 +180,8 @@ GLFWbool _glfwInitOSMesa(void)
|
||||
|
||||
void _glfwTerminateOSMesa(void)
|
||||
{
|
||||
if (_glfw.osmesa.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.osmesa.handle);
|
||||
_glfw.osmesa.handle = NULL;
|
||||
}
|
||||
_glfwPlatformFreeModule(_glfw.osmesa.handle);
|
||||
_glfw.osmesa.handle = NULL;
|
||||
}
|
||||
|
||||
#define SET_ATTRIB(a, v) \
|
||||
|
||||
@@ -41,7 +41,8 @@ void* _glfwPlatformLoadModule(const char* path)
|
||||
|
||||
void _glfwPlatformFreeModule(void* module)
|
||||
{
|
||||
dlclose(module);
|
||||
if (module)
|
||||
dlclose(module);
|
||||
}
|
||||
|
||||
GLFWproc _glfwPlatformGetModuleSymbol(void* module, const char* name)
|
||||
|
||||
@@ -157,8 +157,8 @@ GLFWbool _glfwInitVulkan(int mode)
|
||||
|
||||
void _glfwTerminateVulkan(void)
|
||||
{
|
||||
if (_glfw.vk.handle)
|
||||
_glfwPlatformFreeModule(_glfw.vk.handle);
|
||||
_glfwPlatformFreeModule(_glfw.vk.handle);
|
||||
_glfw.vk.handle = NULL;
|
||||
}
|
||||
|
||||
const char* _glfwGetVulkanResultString(VkResult result)
|
||||
|
||||
@@ -521,8 +521,8 @@ GLFWbool _glfwInitWGL(void)
|
||||
|
||||
void _glfwTerminateWGL(void)
|
||||
{
|
||||
if (_glfw.wgl.instance)
|
||||
_glfwPlatformFreeModule(_glfw.wgl.instance);
|
||||
_glfwPlatformFreeModule(_glfw.wgl.instance);
|
||||
_glfw.wgl.instance = NULL;
|
||||
}
|
||||
|
||||
#define SET_ATTRIB(a, v) \
|
||||
|
||||
@@ -166,29 +166,6 @@ static GLFWbool loadLibraries(void)
|
||||
return GLFW_TRUE;
|
||||
}
|
||||
|
||||
// Unload used libraries (DLLs)
|
||||
//
|
||||
static void freeLibraries(void)
|
||||
{
|
||||
if (_glfw.win32.xinput.instance)
|
||||
_glfwPlatformFreeModule(_glfw.win32.xinput.instance);
|
||||
|
||||
if (_glfw.win32.dinput8.instance)
|
||||
_glfwPlatformFreeModule(_glfw.win32.dinput8.instance);
|
||||
|
||||
if (_glfw.win32.user32.instance)
|
||||
_glfwPlatformFreeModule(_glfw.win32.user32.instance);
|
||||
|
||||
if (_glfw.win32.dwmapi.instance)
|
||||
_glfwPlatformFreeModule(_glfw.win32.dwmapi.instance);
|
||||
|
||||
if (_glfw.win32.shcore.instance)
|
||||
_glfwPlatformFreeModule(_glfw.win32.shcore.instance);
|
||||
|
||||
if (_glfw.win32.ntdll.instance)
|
||||
_glfwPlatformFreeModule(_glfw.win32.ntdll.instance);
|
||||
}
|
||||
|
||||
// Create key code translation tables
|
||||
//
|
||||
static void createKeyTables(void)
|
||||
@@ -721,7 +698,14 @@ void _glfwTerminateWin32(void)
|
||||
_glfwTerminateEGL();
|
||||
_glfwTerminateOSMesa();
|
||||
|
||||
freeLibraries();
|
||||
_glfwPlatformFreeModule(_glfw.win32.xinput.instance);
|
||||
_glfwPlatformFreeModule(_glfw.win32.dinput8.instance);
|
||||
_glfwPlatformFreeModule(_glfw.win32.user32.instance);
|
||||
_glfwPlatformFreeModule(_glfw.win32.dwmapi.instance);
|
||||
_glfwPlatformFreeModule(_glfw.win32.shcore.instance);
|
||||
_glfwPlatformFreeModule(_glfw.win32.ntdll.instance);
|
||||
|
||||
memset(&_glfw.win32, 0, sizeof(_glfw.win32));
|
||||
}
|
||||
|
||||
#endif // _GLFW_WIN32
|
||||
|
||||
@@ -39,7 +39,8 @@ void* _glfwPlatformLoadModule(const char* path)
|
||||
|
||||
void _glfwPlatformFreeModule(void* module)
|
||||
{
|
||||
FreeLibrary((HMODULE) module);
|
||||
if (module)
|
||||
FreeLibrary((HMODULE) module);
|
||||
}
|
||||
|
||||
GLFWproc _glfwPlatformGetModuleSymbol(void* module, const char* name)
|
||||
|
||||
@@ -984,43 +984,16 @@ void _glfwTerminateWayland(void)
|
||||
|
||||
// Free modules only after all Wayland termination functions are called
|
||||
|
||||
if (_glfw.egl.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.egl.handle);
|
||||
_glfw.egl.handle = NULL;
|
||||
}
|
||||
|
||||
if (_glfw.wl.libdecor.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.wl.libdecor.handle);
|
||||
_glfw.wl.libdecor.handle = NULL;
|
||||
}
|
||||
|
||||
if (_glfw.wl.egl.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.wl.egl.handle);
|
||||
_glfw.wl.egl.handle = NULL;
|
||||
}
|
||||
|
||||
if (_glfw.wl.xkb.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.wl.xkb.handle);
|
||||
_glfw.wl.xkb.handle = NULL;
|
||||
}
|
||||
|
||||
if (_glfw.wl.cursor.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.wl.cursor.handle);
|
||||
_glfw.wl.cursor.handle = NULL;
|
||||
}
|
||||
|
||||
if (_glfw.wl.client.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.wl.client.handle);
|
||||
_glfw.wl.client.handle = NULL;
|
||||
}
|
||||
_glfwPlatformFreeModule(_glfw.egl.handle);
|
||||
_glfwPlatformFreeModule(_glfw.wl.libdecor.handle);
|
||||
_glfwPlatformFreeModule(_glfw.wl.egl.handle);
|
||||
_glfwPlatformFreeModule(_glfw.wl.xkb.handle);
|
||||
_glfwPlatformFreeModule(_glfw.wl.cursor.handle);
|
||||
_glfwPlatformFreeModule(_glfw.wl.client.handle);
|
||||
|
||||
_glfw_free(_glfw.wl.clipboardString);
|
||||
|
||||
memset(&_glfw.wl, 0, sizeof(_glfw.wl));
|
||||
}
|
||||
|
||||
#endif // _GLFW_WAYLAND
|
||||
|
||||
@@ -1592,71 +1592,29 @@ void _glfwTerminateX11(void)
|
||||
_glfw.x11.display = NULL;
|
||||
}
|
||||
|
||||
if (_glfw.x11.x11xcb.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.x11.x11xcb.handle);
|
||||
_glfw.x11.x11xcb.handle = NULL;
|
||||
}
|
||||
|
||||
if (_glfw.x11.xcursor.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.x11.xcursor.handle);
|
||||
_glfw.x11.xcursor.handle = NULL;
|
||||
}
|
||||
|
||||
if (_glfw.x11.randr.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.x11.randr.handle);
|
||||
_glfw.x11.randr.handle = NULL;
|
||||
}
|
||||
|
||||
if (_glfw.x11.xinerama.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.x11.xinerama.handle);
|
||||
_glfw.x11.xinerama.handle = NULL;
|
||||
}
|
||||
|
||||
if (_glfw.x11.xrender.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.x11.xrender.handle);
|
||||
_glfw.x11.xrender.handle = NULL;
|
||||
}
|
||||
|
||||
if (_glfw.x11.xshape.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.x11.xshape.handle);
|
||||
_glfw.x11.xshape.handle = NULL;
|
||||
}
|
||||
|
||||
if (_glfw.x11.vidmode.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.x11.vidmode.handle);
|
||||
_glfw.x11.vidmode.handle = NULL;
|
||||
}
|
||||
|
||||
if (_glfw.x11.xi.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.x11.xi.handle);
|
||||
_glfw.x11.xi.handle = NULL;
|
||||
}
|
||||
|
||||
_glfwTerminateOSMesa();
|
||||
// NOTE: These need to be unloaded after XCloseDisplay, as they register
|
||||
// cleanup callbacks that get called by that function
|
||||
_glfwTerminateEGL();
|
||||
_glfwTerminateGLX();
|
||||
|
||||
if (_glfw.x11.xlib.handle)
|
||||
{
|
||||
_glfwPlatformFreeModule(_glfw.x11.xlib.handle);
|
||||
_glfw.x11.xlib.handle = NULL;
|
||||
}
|
||||
_glfwPlatformFreeModule(_glfw.x11.x11xcb.handle);
|
||||
_glfwPlatformFreeModule(_glfw.x11.xcursor.handle);
|
||||
_glfwPlatformFreeModule(_glfw.x11.randr.handle);
|
||||
_glfwPlatformFreeModule(_glfw.x11.xinerama.handle);
|
||||
_glfwPlatformFreeModule(_glfw.x11.xrender.handle);
|
||||
_glfwPlatformFreeModule(_glfw.x11.xshape.handle);
|
||||
_glfwPlatformFreeModule(_glfw.x11.vidmode.handle);
|
||||
_glfwPlatformFreeModule(_glfw.x11.xi.handle);
|
||||
_glfwPlatformFreeModule(_glfw.x11.xlib.handle);
|
||||
|
||||
if (_glfw.x11.emptyEventPipe[0] || _glfw.x11.emptyEventPipe[1])
|
||||
{
|
||||
close(_glfw.x11.emptyEventPipe[0]);
|
||||
close(_glfw.x11.emptyEventPipe[1]);
|
||||
}
|
||||
|
||||
memset(&_glfw.x11, 0, sizeof(_glfw.x11));
|
||||
}
|
||||
|
||||
#endif // _GLFW_X11
|
||||
|
||||
Reference in New Issue
Block a user