From 20f66ff0b46c9d410736e5d38c3e24b63a38926a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 2 Aug 2025 13:15:39 +0200 Subject: [PATCH] Platform: delete EmscriptenApplication WebGL context only if there is. --- src/Magnum/Platform/EmscriptenApplication.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Magnum/Platform/EmscriptenApplication.cpp b/src/Magnum/Platform/EmscriptenApplication.cpp index 483ef7262..a994522c4 100644 --- a/src/Magnum/Platform/EmscriptenApplication.cpp +++ b/src/Magnum/Platform/EmscriptenApplication.cpp @@ -252,10 +252,18 @@ EmscriptenApplication::EmscriptenApplication(const Arguments& arguments, NoCreat EmscriptenApplication::~EmscriptenApplication() { #ifdef MAGNUM_TARGET_GL /* Destroy Magnum context first to avoid it potentially accessing the - now-destroyed GL context after */ + now-destroyed GL context after. If the application was created with + WindowFlag::Contextless set, the optional is still populated but with + _context->tryCreate() not set yet. The only way to check whether it's + actually created is to check for version, consistently with the assert + in the GL tryCreate() implementation below. */ + bool hasContext = _context->version() != GL::Version::None; _context = Containers::NullOpt; - emscripten_webgl_destroy_context(_glContext); + /* Destroy WebGL context only if there actually was one */ + CORRADE_INTERNAL_ASSERT(hasContext == !!_glContext); + if(hasContext) + emscripten_webgl_destroy_context(_glContext); #endif }