Browse Source

Partially undo commits #99186e5 and #89d938d and use less-intrusive, JUCE-internal fix for OpenGLContext detach crash

Fixes #88
tags/2021-05-28
hogliux 9 years ago
parent
commit
c7b347242d
5 changed files with 33 additions and 19 deletions
  1. +0
    -9
      modules/juce_core/memory/juce_WeakReference.h
  2. +2
    -5
      modules/juce_gui_basics/components/juce_Component.cpp
  3. +9
    -1
      modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm
  4. +2
    -4
      modules/juce_gui_extra/native/juce_mac_NSViewComponent.mm
  5. +20
    -0
      modules/juce_opengl/native/juce_OpenGL_osx.h

+ 0
- 9
modules/juce_core/memory/juce_WeakReference.h View File

@@ -193,15 +193,6 @@ public:
sharedPointer->clearPointer();
}
/** Returns a raw pointer to the underlying object. */
ObjectType* get() const noexcept
{
if (sharedPointer != nullptr)
return sharedPointer->get();
return nullptr;
}
private:
SharedRef sharedPointer;


+ 2
- 5
modules/juce_gui_basics/components/juce_Component.cpp View File

@@ -710,13 +710,10 @@ void Component::removeFromDesktop()
ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
jassert (peer != nullptr);
ScopedPointer<ComponentPeer> oldPeerToDelete (peer);
flags.hasHeavyweightPeerFlag = false;
Desktop::getInstance().removeDesktopComponent (this);
delete peer;
if (masterReference.get() != nullptr)
internalHierarchyChanged();
Desktop::getInstance().removeDesktopComponent (this);
}
}


+ 9
- 1
modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm View File

@@ -58,6 +58,10 @@ static NSRect flippedScreenRect (NSRect r) noexcept
return r;
}
#if JUCE_MODULE_AVAILABLE_juce_opengl
void componentPeerAboutToBeRemovedFromScreen (ComponentPeer&);
#endif
//==============================================================================
class NSViewComponentPeer : public ComponentPeer,
private AsyncUpdater
@@ -674,8 +678,12 @@ public:
void redirectWillMoveToWindow (NSWindow* newWindow)
{
#if JUCE_MODULE_AVAILABLE_juce_opengl
if ([view window] == window && newWindow == nullptr)
getComponent().removeFromDesktop();
componentPeerAboutToBeRemovedFromScreen (*this);
#else
ignoreUnused (newWindow);
#endif
}
void sendMouseEvent (NSEvent* ev)


+ 2
- 4
modules/juce_gui_extra/native/juce_mac_NSViewComponent.mm View File

@@ -199,12 +199,10 @@ void NSViewComponent::setView (void* const view)
{
if (view != getView())
{
ReferenceCountedObject* object = nullptr;
attachment = nullptr;
if (view != nullptr)
object = attachViewToComponent (*this, view);
attachment = object;
attachment = attachViewToComponent (*this, view);
}
}


+ 20
- 0
modules/juce_opengl/native/juce_OpenGL_osx.h View File

@@ -243,3 +243,23 @@ bool OpenGLHelpers::isContextActive()
{
return CGLGetCurrentContext() != 0;
}
//==============================================================================
void componentPeerAboutToBeRemovedFromScreen (ComponentPeer& peer)
{
Array<Component*> stack;
stack.add (&peer.getComponent());
while (stack.size() != 0)
{
Component& comp = *stack.removeAndReturn (0);
const int n = comp.getNumChildComponents();
for (int i = 0; i < n; ++i)
if (Component* child = comp.getChildComponent (i))
stack.add (child);
if (OpenGLContext* context = OpenGLContext::getContextAttachedTo (comp))
context->detach();
}
}

Loading…
Cancel
Save