OpenGL + VBO + C#

Started by
7 comments, last by Kobayashi 16 years, 11 months ago
Hello everybody! I have problem with using OpenGL extension in C#. When i am using sth like this: gr.glGenBuffersARB(1, _terview._vertex_buffer); I get error : An unhandled exception of type 'System.NullReferenceException' occurred in Terrain Viewer.exe Additional information: Object reference not set to an instance of an object. In constructor of _terview class i have created an instance of _vertex_buffer: _vertex_buffer = new int[1]; So everything should be ok, but it isnt. If anyone can help me with this extensions i would be grateful:d
Advertisement
I don't know C# ...

But you may check if:

- that extension is supported by your graphic card ?

- how you assign the glGenBufferARB function: how do you load the extension ? do you use a parser like glee or glew ( I don't know the C# version) ? Or do you have to do the assignment yourself ( gr.glGenBuffersARB = wglgetProcAddress ...) ?
jma
I am using class created by Colin Fahey, there is everything you need, and you neednt to worry about this stuff. Its just this error that i am concerned about.
I suggest using the tao framework instead.
Its not about framework, i used CSGL liblary too, and this error exposed there too.
I will get close to You architecture of this app, so someone can see, maybe this is my error or sthg:

//class #1
class Terview
{
public CTerrain _terrain;
public GRControl _oglcontrol;
/........./
public Terview()
{
_terrain = new CTerrain();
GR gr = _oglcontrol.GetGR();

gr.glGenBuffersARB(1, _terview._vertex_buffer); //error!
/......./
}
/...../
}

//Class #2
public class CTerrain
{
public int[] _vertex_buffer;
/................/

public CTerrain()
{
_vertex_buffer = new int[1];
/..................../
}
/..................../
};
Have you tried running it in the debugger to see where the null reference exception is being triggered from? From the provided source, it looks like you never set (or use) _oglcontrol.
I finnally got it!
I step into

public void glGenBuffersARB ( int n, int[] buffers )
{
mDglGenBuffersARB_IaI( n, buffers ); //->> this is delegate that gives error
}
But i am still confused, is there something that can be done to avoid this error?
I guess i must read more about this new stuff in c#, but if anyone can point me how to avoid this error it could be great!

[Edited by - Kobayashi on May 22, 2007 11:35:50 AM]
The problem is that your delegate is actually a wrapper around a pointer to the extension function, and is null.

There's two possible causes:

1) Your video card doesn't support this extension (so that the function that retrieves the pointer returns null).

2) The function isn't being setup, whether because of a bug in the code or because of a step you missed.

CSGL is pretty old. I'd switch to the tao framework, as snk_kid suggested.
I am not using CSGL only Colin Fahey class - CPF.GRV10.GRControl.cs.

And i figure it out now : i am using extension inside a delegate function:

_oglcontrol.OpenGLStarted += new GRControl.DelegateOpenGLStarted(this.OpenGLStarted);

I am using extension in
OpenGLStarted function and everything is ok now, but thnx anyway.

This topic is closed to new replies.

Advertisement