Bug 19042 - ClassCast exception with IGL11ExtensionPack in OpenGL
Summary: ClassCast exception with IGL11ExtensionPack in OpenGL
Status: RESOLVED INVALID
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 4.12.3
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Atsushi Eno
URL:
Depends on:
Blocks:
 
Reported: 2014-04-14 16:23 UTC by Jared Oates
Modified: 2014-04-15 17:22 UTC (History)
1 user (show)

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


Attachments
Modified ApiDemo sample code (3.94 MB, application/octet-stream)
2014-04-14 19:48 UTC, Jared Oates
Details


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 INVALID

Description Jared Oates 2014-04-14 16:23:37 UTC
I get an InvalidCastException when I cast the IGL10 object that is passed to the OnSurfaceCreated method of a GLSurfaceView.IRenderer to an IGL11ExtensionPack.

This is the standard Android mechanism for using the extension pack methods as far as I'm aware.  

This makes it impossible for me to use any of the extension methods in the IGL11ExtensionPack, generating a RenderBuffer using the GlGenRenderbuffersOES() method, for example.

I've attached a modified version of the API Demo sample solution that will reproduce the error. Simply deploy the solution and go to Graphics/SurfaceView Overlay

Here's the stack trace:
System.InvalidCastException: Cannot cast from source type to destination type.
  at MonoDroid.ApiDemo.CubeRenderer.OnSurfaceCreated (Javax.Microedition.Khronos.Opengles.IGL10,Javax.Microedition.Khronos.Egl.EGLConfig) [0x00001] in /Users/i53143/workspaces/monodroid-samples-master/ApiDemo/Graphics/CubeRenderer.cs:93
  at Android.Opengl.GLSurfaceView/IRendererInvoker.n_OnSurfaceCreated_Ljavax_microedition_khronos_opengles_GL10_Ljavax_microedition_khronos_egl_EGLConfig_ (intptr,intptr,intptr,intptr) [0x00019] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/7f0e3d3c/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Opengl.GLSurfaceView.cs:551
  at at (wrapper dynamic-method) object.7a2fe63c-8392-4ad0-afe2-a3b7b073ed68 (intptr,intptr,intptr,intptr) <IL 0x0001d, 0x0004b>
Comment 1 Atsushi Eno 2014-04-14 19:43:40 UTC
How do you actually cast? If you use JavaCast<T>() and still seeing InvalidCastException please provide some reproducible code that causes the problem.
Comment 2 Jared Oates 2014-04-14 19:48:04 UTC
Created attachment 6581 [details]
Modified ApiDemo sample code

I guess the attachment didn't save when I created the bug.
Comment 3 Atsushi Eno 2014-04-15 03:35:47 UTC
			// At this point we get a class cast exception
			IGL11ExtensionPack ext = (IGL11ExtensionPack)gl;


As I wrote earlier, JavaCast<T>() is required. You cannot use C# cast.

The code above must be:

			IGL11ExtensionPack ext = gl.JavaCast<IGL11ExtensionPack>();

(And add "using Java.Interop;" to actually use that extension method.)