From 4de9f75e1c1031ff1b43a887aa6d9dcba2ab6dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 25 Feb 2021 12:37:36 +0100 Subject: [PATCH] GL: make the Context::makeCurrent() test more robust. So if it fails somewhere, the current context is reset back. --- src/Magnum/GL/Test/ContextGLTest.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Magnum/GL/Test/ContextGLTest.cpp b/src/Magnum/GL/Test/ContextGLTest.cpp index 362ec5970..f6c7df05c 100644 --- a/src/Magnum/GL/Test/ContextGLTest.cpp +++ b/src/Magnum/GL/Test/ContextGLTest.cpp @@ -242,26 +242,27 @@ void ContextGLTest::constructConfiguration() { void ContextGLTest::makeCurrent() { CORRADE_VERIFY(Context::hasCurrent()); - - Context& current = Context::current(); - Context::makeCurrent(nullptr); - - CORRADE_VERIFY(!Context::hasCurrent()); + Context* current = &Context::current(); { - Platform::GLContext ctx{Context::Configuration{} - .setFlags(Context::Configuration::Flag::QuietLog) - }; + Context::makeCurrent(nullptr); + Containers::ScopeGuard resetCurrent{current, Context::makeCurrent}; - CORRADE_VERIFY(Context::hasCurrent()); - } + CORRADE_VERIFY(!Context::hasCurrent()); - CORRADE_VERIFY(!Context::hasCurrent()); + { + Platform::GLContext ctx{Context::Configuration{} + .setFlags(Context::Configuration::Flag::QuietLog) + }; - Context::makeCurrent(¤t); + CORRADE_VERIFY(Context::hasCurrent()); + } + + CORRADE_VERIFY(!Context::hasCurrent()); + } CORRADE_VERIFY(Context::hasCurrent()); - CORRADE_COMPARE(&Context::current(), ¤t); + CORRADE_COMPARE(&Context::current(), current); } #ifndef CORRADE_TARGET_EMSCRIPTEN