Bug 13421 - [Possible Regression] Bug #12212: Fix disposal of EAGLContext and GraphicsContext
Summary: [Possible Regression] Bug #12212: Fix disposal of EAGLContext and GraphicsCon...
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 6.3.x
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: 6.4.x (post async)
Assignee: Rolf Bjarne Kvinge [MSFT]
Depends on:
Reported: 2013-07-23 16:37 UTC by Pierce Boggan [MSFT]
Modified: 2013-09-27 09:51 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

EAGLContext becomes null (10.80 KB, application/zip)
2013-07-29 18:18 UTC, Marco Lancione

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Pierce Boggan [MSFT] 2013-07-23 16:37:48 UTC
Description of Issue: Customer reported an issue in 6.3.8 that was fixed in 6.3.6. Believes it is related to Bug #12212 that was fixed in 6.3.6:
Fix disposal of EAGLContext and GraphicsContext to avoid exceptions [#12212] (from the Xamarin.iOS release notes)

Logs: Attached.

Reverting back to 6.3.6 fixed issue, so looks like a possible regression.

Here is the Xamarin info:
=== Xamarin Studio ===

Version 4.0.10 (build 5)
Installation UUID: c0cff6c3-82c4-47ab-95d4-d4952faa7115
Mono 3.1.2 ((no/71af847)
GTK 2.24.20
GTK# (
Package version: 301020000

=== Apple Developer Tools ===

Xcode 4.6.3 (2068)
Build 4H1503

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: bc5a95b
Build date: 2013-17-07 15:48:27-0400

=== Xamarin.Android ===

Version: 4.8.0 (Starter Edition)
Android SDK: /Users/wwang/Library/Developer/Xamarin/android-sdk-mac_x86
Supported Android versions:
2.1   (API level 7)
2.2   (API level 8)
2.3   (API level 10)
3.1   (API level 12)
4.0   (API level 14)
4.0.3 (API level 15)
Java SDK: /usr
java version "1.6.0_51"
Java(TM) SE Runtime Environment (build 1.6.0_51-b11-456-11M4508)
Java HotSpot(TM) 64-Bit Server VM (build 20.51-b01-456, mixed mode)

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Build Information ===

Release ID: 400100005
Git revision: f78b1117e201b3890dce45559bc8995adc4005a2
Build date: 2013-07-15 16:16:13+0000
Xamarin addins: a158bb2e0120450d0d23a35a5d4cbc695947bcab

=== Operating System ===

Mac OS X 10.8.4
Darwin Williams-iMac.local 12.4.0 Darwin Kernel Version 12.4.0
    Wed May  1 17:57:12 PDT 2013
    root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64
Comment 2 Sebastien Pouliot 2013-07-23 20:59:58 UTC
The patch for #12212 is still there and included in the latest builds.

$ git branch --contains 938cf69518205d26fe4243dca1a0b6cdf8dbb46a
* master-3.0

Please attach your test case to reproduce the issue.
Comment 3 Marco Lancione 2013-07-27 12:42:27 UTC
This problem appears to still be present in 6.4.0.  I believe it's related to a GC issue related to IGraphicsContextInternal object being disposed of.

If the iPhoneOSGraphicsContext object is created as follows the EAGLContext object eventually gets disposed of prematurely:
Context = (iPhoneOSGraphicsContext)( (IGraphicsContextInternal)Utilities.CreateGraphicsContext(EAGLRenderingAPI.OpenGLES2) ).Implementation;

However, if a handle to the IGraphicsContextInternal object is kept the problem seems to not exhibit itself:
ContextInternal = (IGraphicsContextInternal)Utilities.CreateGraphicsContext(EAGLRenderingAPI.OpenGLES2);
Context = (iPhoneOSGraphicsContext)ContextInternal.Implementation;

Here is an OpenTK post regarding an issue that sounds very similar:
Comment 4 Marco Lancione 2013-07-29 18:18:31 UTC
Created attachment 4476 [details]
EAGLContext becomes null

Sample project where EAGLContext eventually becomes null.  Sample modified from https://github.com/chrisntr/monotouch-samples/tree/master/OpenGLESSample (only Context assignment line modified).
Comment 5 Rolf Bjarne Kvinge [MSFT] 2013-07-29 19:39:20 UTC
I can reproduce a NRE with that test case, I'll have a look.
Comment 7 Marco Lancione 2013-08-27 19:02:47 UTC
Any update on this issue?
Comment 8 Rolf Bjarne Kvinge [MSFT] 2013-09-27 09:51:19 UTC
I've looked into this now, and I'm not sure there is a bug.

You're creating a GraphicsContext, then fetching its implementation and forgetting about the GraphicsContext you just created.

Then the GraphicsContext is freed, and will dispose its implementation, causing the NRE.

The sample runs successfully if you store the GraphicsContext in the EAGLView instance.