
null reference
Posted Wednesday, 21 October, 2009 - 13:54 by AdrianPi inHello,
I'm dynamically loading and assembly wich in turns uses OpenTK. I needed to override AppDomain's AssemblyResolve to load the OpenTK assembly. However when I call any GL class function (GetString, for instance) I get a null reference exception ("Object not set to an instance of an object").
An OpenGL context is already created and active. ¿Do I need to initialize something?
Any help would be appreciated. Thanks in advance.


Comments
Re: null reference
Yes, please see this post: http://www.opentk.com/node/1258#comment-6862
If it is not possible to have OpenTK create the context, you will have to use reflection to call the equivalent of:
Both the GL constructor and the LoadAll method are non-public (hence the need for reflection). The next version of OpenTK will provide a better way to initialize the OpenGL bindings.
Re: null reference
Thanks for your prompt reply.
I'm trying with this:
But the exception "Exception has been thrown by the target of an invocation" is thrown.
¿Am I doing something wrong? ¿Why the "new" keyword in your snippet?
Re: null reference
You need to create an instance of the GL class first. Check out Activator.CreateInstance.
Re: null reference
Isn't GL a static class?
I added the call to the constructor:
Still not luck and getting TargetInvocationException.
Sorry for the message boxes, but I found no better way to log errors inside an ActiveX control inside the ActiveX test container...
Re: null reference
No, neither GL nor LoadAll() are static anymore. (They used to be several months ago, but they were modified so they can inherit from a common base class).
Try this:
Re: null reference
I get "Cannot create an instance of OpenTK.Graphics.GL because it is an abstract class.
I'll try a big refactor and create the rendering context on the .net side and not on the activex (C++)...
Re: null reference
Alright.
I just want to say that this error message is pretty strange, as OpenTK does create instances of the GL class internally. Maybe you are using an older version of OpenTK? This needs 0.9.9-2b or 0.9.9-3 to work.
Re: null reference
It's 0.9.9-3, release, downloaded yesterday. ¿Do you thinks downloading the sources and compiling it will help?
Re: null reference
Ok, I can see the issue now. You are reflecting on OpenTK.Graphics.GL from OpenTK.Compatibility, while my code referred to OpenTK.Graphics.OpenGL.GL from core OpenTK.
If you are using OpenTK.Graphics.GL, you can simply call GL.LoadAll() without reflection.
Your reflection code should work correctly if you simply change
typeof(OpenTK.Graphics.GL)totypeof(OpenTK.Graphics.OpenGL.GL).Edit: This code works correctly.
Re: null reference
Good point!
I'm calling GL.LoadAll directly.
But now I get "No graphics context available in the calling thread".
The rendering context has been created in C++ and made active, before calling this C# code via interop.
How can I get OpenTK to know there is an "alien" context created? :)