diff --git a/doc/changelog.dox b/doc/changelog.dox index fcf7da236..de93458bf 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -371,7 +371,9 @@ See also: @ref Corrade::Containers::Array instead of being deleted - Global state used by @ref GL::Context and @ref Audio::Context is no longer duplicated when Magnum is built statically and linked to more than one - dynamic library or executable. + dynamic library or executable. This works on all platforms except for + Python bindings on Windows at the moment, where the workaround is to build + both Corrade and Magnum dynamically. - The [base-qt](https://github.com/mosra/magnum-bootstrap/tree/base-qt) bootstrap project is fixed to use OpenGL 4.1 on macOS instead of being stuck on 2.1 (see [mosra/magnum-bootstrap#22](https://github.com/mosra/magnum-bootstrap/issues/22)) diff --git a/src/Magnum/Audio/Context.cpp b/src/Magnum/Audio/Context.cpp index d099b258f..9e531b3ef 100644 --- a/src/Magnum/Audio/Context.cpp +++ b/src/Magnum/Audio/Context.cpp @@ -161,7 +161,7 @@ namespace { Context*& windowsCurrentContext() { /* A function-local static to ensure it's only initialized once without any race conditions among threads */ - static Context** const uniqueGlobals = reinterpret_cast(Magnum::Implementation::windowsWeakSymbol("magnumAudioUniqueCurrentContext")); + static Context** const uniqueGlobals = reinterpret_cast(Magnum::Implementation::windowsWeakSymbol("magnumAudioUniqueCurrentContext", &magnumAudioUniqueCurrentContext)); return *uniqueGlobals; } diff --git a/src/Magnum/GL/Context.cpp b/src/Magnum/GL/Context.cpp index 5c8e30b3f..c89b3eaa5 100644 --- a/src/Magnum/GL/Context.cpp +++ b/src/Magnum/GL/Context.cpp @@ -522,7 +522,7 @@ namespace { Context*& windowsCurrentContext() { /* A function-local static to ensure it's only initialized once without any race conditions among threads */ - static Context*&(*const uniqueGlobals)() = reinterpret_cast(Magnum::Implementation::windowsWeakSymbol("magnumGLUniqueCurrentContext")); + static Context*&(*const uniqueGlobals)() = reinterpret_cast(Magnum::Implementation::windowsWeakSymbol("magnumGLUniqueCurrentContext", reinterpret_cast(magnumGLUniqueCurrentContext))); return uniqueGlobals(); } diff --git a/src/Magnum/Implementation/WindowsWeakSymbol.cpp b/src/Magnum/Implementation/WindowsWeakSymbol.cpp index 619cc606c..9de17ffd6 100644 --- a/src/Magnum/Implementation/WindowsWeakSymbol.cpp +++ b/src/Magnum/Implementation/WindowsWeakSymbol.cpp @@ -25,7 +25,7 @@ #include "WindowsWeakSymbol.h" -#include +#include #define WIN32_LEAN_AND_MEAN 1 #define VC_EXTRALEAN @@ -33,10 +33,15 @@ namespace Magnum { namespace Implementation { -void* windowsWeakSymbol(const char* name) { +void* windowsWeakSymbol(const char* name, void* backup) { /* FARPROC?! I want either a function pointer or a variable pointer */ void* address = reinterpret_cast(GetProcAddress(GetModuleHandleA(nullptr), name)); - CORRADE_INTERNAL_ASSERT(address); + /* This shouldn't fail, except in Python, where it's a sad, sad misery. */ + if(!address) { + std::fprintf(stderr, "Cannot query global symbol %s and make it unique\n" + "across DLLs. App may misbehave, sorry. Build Magnum as dynamic as a workaround.\n", name); + address = backup; + } return address; } diff --git a/src/Magnum/Implementation/WindowsWeakSymbol.h b/src/Magnum/Implementation/WindowsWeakSymbol.h index b5bd7bbfd..6251338a6 100644 --- a/src/Magnum/Implementation/WindowsWeakSymbol.h +++ b/src/Magnum/Implementation/WindowsWeakSymbol.h @@ -39,7 +39,7 @@ namespace Magnum { namespace Implementation { -void* windowsWeakSymbol(const char* name); +void* windowsWeakSymbol(const char* name, void* backup); }}