diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp index 45c99ae0ee..27faff4510 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp @@ -145,11 +145,6 @@ public: { ScopedPointer mmLock; - const Rectangle screenBounds (component.getTopLevelComponent()->getScreenBounds()); - - if (lastScreenBounds != screenBounds) - updateViewportSize (false); - const bool isUpdating = needsUpdate.compareAndSetBool (0, 1); if (context.renderComponents && isUpdating) @@ -161,6 +156,8 @@ public: mmLock = new MessageManagerLock (this); // need to acquire this before locking the context. if (! mmLock->lockWasGained()) return false; + + updateViewportSize (false); } if (! context.makeActive()) @@ -219,13 +216,19 @@ public: } } + void checkViewportBounds() + { + const Rectangle screenBounds (component.getTopLevelComponent()->getScreenBounds()); + + if (lastScreenBounds != screenBounds) + updateViewportSize (true); + } + void paintComponent() { // you mustn't set your own cached image object when attaching a GL context! jassert (get (component) == this); - updateViewportSize (false); - if (! ensureFrameBufferSize()) return; @@ -463,7 +466,8 @@ void OpenGLContext::NativeContext::renderCallback() #endif //============================================================================== -class OpenGLContext::Attachment : public ComponentMovementWatcher +class OpenGLContext::Attachment : public ComponentMovementWatcher, + private Timer { public: Attachment (OpenGLContext& c, Component& comp) @@ -564,10 +568,14 @@ private: comp.setCachedComponentImage (newCachedImage); newCachedImage->start(); // (must wait until this is attached before starting its thread) newCachedImage->updateViewportSize (true); + + startTimer (400); } void detach() { + stopTimer(); + Component& comp = *getComponent(); #if JUCE_MAC @@ -580,6 +588,12 @@ private: comp.setCachedComponentImage (nullptr); context.nativeContext = nullptr; } + + void timerCallback() override + { + if (CachedImage* const cachedImage = CachedImage::get (*getComponent())) + cachedImage->checkViewportBounds(); + } }; //==============================================================================