Skip to content

Commit

Permalink
Partially undo commits #99186e5 and #89d938d and use less-intrusive, …
Browse files Browse the repository at this point in the history
…JUCE-internal fix for OpenGLContext detach crash

Fixes #88
  • Loading branch information
hogliux committed Aug 11, 2016
1 parent 8f7d9f7 commit c7b3472
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
9 changes: 0 additions & 9 deletions modules/juce_core/memory/juce_WeakReference.h
Expand Up @@ -193,15 +193,6 @@ class WeakReference
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;

Expand Down
7 changes: 2 additions & 5 deletions modules/juce_gui_basics/components/juce_Component.cpp
Expand Up @@ -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);
}
}

Expand Down
10 changes: 9 additions & 1 deletion modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm
Expand Up @@ -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
Expand Down Expand Up @@ -674,8 +678,12 @@ void redirectMagnify (NSEvent* ev)

void redirectWillMoveToWindow (NSWindow* newWindow)
{
#if JUCE_MODULE_AVAILABLE_juce_opengl
if ([view window] == window && newWindow == nullptr)
getComponent().removeFromDesktop();
componentPeerAboutToBeRemovedFromScreen (*this);

This comment has been minimized.

Copy link
@yairchu

yairchu Oct 25, 2016

In Steinberg Wavelab 7.2.1 this happens when the component is first opened, and causes the OpenGL context to detach.
When later the component is moved to a window nothing causes it to reattach - so this causes OpenGL to simply not work in plugins in Wavelab in OS X..

This comment has been minimized.

Copy link
@yairchu

yairchu Oct 25, 2016

Should something like

if ([view window] == window)
    setVisible (newWindow != nullptr);

instead work?
it seems to work well in Wavelab but I don't know if it has undesirable implications..

#else
ignoreUnused (newWindow);
#endif
}

void sendMouseEvent (NSEvent* ev)
Expand Down
6 changes: 2 additions & 4 deletions modules/juce_gui_extra/native/juce_mac_NSViewComponent.mm
Expand Up @@ -199,12 +199,10 @@ void removeFromParent()
{
if (view != getView())
{
ReferenceCountedObject* object = nullptr;
attachment = nullptr;

if (view != nullptr)
object = attachViewToComponent (*this, view);

attachment = object;
attachment = attachViewToComponent (*this, view);
}
}

Expand Down
20 changes: 20 additions & 0 deletions modules/juce_opengl/native/juce_OpenGL_osx.h
Expand Up @@ -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();
}
}

0 comments on commit c7b3472

Please sign in to comment.