Bug 1019 - Remedy of Bug 691 causes 'access/modify after free' and crashes the app on OSX
Summary: Remedy of Bug 691 causes 'access/modify after free' and crashes the app on OSX
Status: RESOLVED FIXED
Alias: None
Product: Jogl
Classification: JogAmp
Component: macosx (show other bugs)
Version: 2
Hardware: All macosx
: --- critical
Assignee: Sven Gothel
URL:
Depends on:
Blocks: 691
  Show dependency treegraph
 
Reported: 2014-06-12 08:18 CEST by Sven Gothel
Modified: 2014-06-12 18:25 CEST (History)
2 users (show)

See Also:
Type: ---
SCM Refs:
5626740d14554acf7a17a73ec12b0893445832d0
Workaround: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Gothel 2014-06-12 08:18:29 CEST
The 'magic' MyNSOpenGLContext::dealloc (MacOSXWindowSystemInterface-calayer.m)
of force destroying the underlying CGLContextObj of it's associated
NSOpenGLContext as introduced as a remedy of Bug 691 is plain wrong.

It was added in commit f6e6fab2a7ddfb5c9b614cb072c27ff697629161
to mitigate the experience behavior of delayed GL context
destruction when creating/destroying them multiple times
as exposed in unit test TestGLCanvasAddRemove01SwingAWT.

While this 'hack' worked for some reason on some OSX versions,
it caused a 'access/modify after free' issue exposed under some circumstances
and crashes the application.

The actual culprit of the delayed GL context destruction is different.
The offthread CALayer detachment and hence final destruction
issued on the main-thread is _not_ issued immediately 
due to some referencing holding by NSApp.
Issuing an empty event on the NSApp (thread) will wake up the thread
and release claimed resources.

This has been found while realizing that the GL context 
are released if the mouse is being moved (duh!).
This issue is also known when triggering stop on the NSApp (NEWT MainThread),
same remedy has been implemented here for a long time.
Comment 1 Sven Gothel 2014-06-12 08:22:45 CEST
commit 5626740d14554acf7a17a73ec12b0893445832d0

fixed as described