diff --git a/modules/juce_opengl/juce_opengl.cpp b/modules/juce_opengl/juce_opengl.cpp index 3938dd566b..6509632284 100644 --- a/modules/juce_opengl/juce_opengl.cpp +++ b/modules/juce_opengl/juce_opengl.cpp @@ -142,6 +142,56 @@ static const char* getGLErrorMessage (const GLenum e) noexcept return "Unknown error"; } +#if JUCE_MAC || JUCE_IOS + + #ifndef JUCE_IOS_MAC_VIEW + #if JUCE_IOS + #define JUCE_IOS_MAC_VIEW UIView + #define JUCE_IOS_MAC_WINDOW UIWindow + #else + #define JUCE_IOS_MAC_VIEW NSView + #define JUCE_IOS_MAC_WINDOW NSWindow + #endif + #endif + +#endif + +static bool checkPeerIsValid (OpenGLContext* context) +{ + jassert (context != nullptr); + + if (context != nullptr) + { + if (auto* comp = context->getTargetComponent()) + { + if (auto* peer = comp->getPeer()) + { + #if JUCE_MAC || JUCE_IOS + if (auto* nsView = (JUCE_IOS_MAC_VIEW*) peer->getNativeHandle()) + { + if (auto* nsWindow = [nsView window]) + { + #if JUCE_MAC + return ([nsWindow isVisible] + && (! [nsWindow hidesOnDeactivate] || [NSApp isActive])); + #else + ignoreUnused (nsWindow); + return true; + #endif + } + } + #else + return true; + #endif + } + } + } + else + jassertfalse; + + return false; +} + static void checkGLError (const char* file, const int line) { for (;;) @@ -151,6 +201,10 @@ static void checkGLError (const char* file, const int line) if (e == GL_NO_ERROR) break; + // if the peer is not valid then ignore errors + if (! checkPeerIsValid (OpenGLContext::getCurrentContext())) + continue; + DBG ("***** " << getGLErrorMessage (e) << " at " << file << " : " << line); jassertfalse; }