Bug 42755 - Crash due to Null Reference Exception in OpenGLViewRenderer
Summary: Crash due to Null Reference Exception in OpenGLViewRenderer
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.3.2
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-07-22 18:54 UTC by Stuart Fischer
Modified: 2017-05-23 18:07 UTC (History)
2 users (show)

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

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:
Status:
RESOLVED FIXED

Description Stuart Fischer 2016-07-22 18:54:19 UTC
In testing my local fix for Bugzilla #41413, (change from using NSRunLoop.NSDefaultRunLoopMode to NSRunLoop.NSRunLoopCommonModes on OpenGLViewRenderer.cs line 101), I observed a crash in OpenGLViewRenderer.cs on line 96, when multiple OpenGLViewRenderers exist in the same app (eg. different Sub-views).

A View (the map in our app) instantiates a Xamarin.Forms OpenGLView (using OpenGLViewRenderer), then another View (a match-3 game on an overlaying view) instantiates a second OpenGLView. Around the time the 2nd view is instantiated, there is a Null Reference Exception on line 96 ("_displayLink.Invalidate()") of OpenGLViewRenderer.cs.

This can happen because the Dispose() method of OpenGLViewRenderer.cs is setting _displayLink to null (on line 45), but the run-loop may thereafter attempt to access the (nulled) _displayLink on line 96. If one adds a guard for null _displayLink to the condition of line 94, the problem no longer occurs:

BEFORE (line 94 of OpenGLViewRenderer.cs):

 if (control == null || model == null || !model.HasRenderLoop)

AFTER, with null guard (line 94):

 if ((control == null || model == null || !model.HasRenderLoop)&&(_displayLink!=null))

I think this adding this null guard on line 94 is one solution to this issue.
Comment 1 Rui Marinho 2017-05-23 18:07:49 UTC
Should be fixed on 2.3.6-pre1