OpenGL, C#, and glGetString - an unusual question.

Started by
8 comments, last by anon72 12 years, 11 months ago
Hello folks. I've recently been tasked with taking a tools application which uses OpenGL via C# from Visual Studio 2005 to VS2010. In the process I've retargetted the application from .Net 2.0 to .Net 4.0. For the most part, everything has gone relatively smoothly, however a couple pieces of the code are now malfunctioning.

One piece is using glGetString calls to retrieve the renderer, version, and vendor information from the current context. Executing this code now results in an exception thrown from within the OpenGL call itself.

The code relating to OpenGL has not changed during this migration, and the application compiled in VS2005 does not show this behavior. I can't help but think if I can figure out what has changed (the code has not) between VS2005 and VS2010 (or between .Net 2.0 and .Net 4.0) then I will be able to track down the other issues as well.

So... Any ideas as to how I might track down the problem that has occurred?
Advertisement
"Executing this code now results in an exception thrown from within the OpenGL call itself."

How sure are you that you actually have a valid context at the point this executes?

Is there a chance that your context creation code fails on your new build (for mumble library related reasons or something) but the return values aren't being checked?

"Executing this code now results in an exception thrown from within the OpenGL call itself."

How sure are you that you actually have a valid context at the point this executes?

Is there a chance that your context creation code fails on your new build (for mumble library related reasons or something) but the return values aren't being checked?


Well, I am sure that the return values are being checked. The context being returned is non-null and being set before glGetString is called. Further, I know that the draw calls are going through correctly, although I don't know the code well enough to guarantee that the context being used for glGetString is the same one as that being used for the drawing - I'll get back to you on that one.
It does appear that the context that we query for glGetString is a different context than that created for performing the actual rendering. Is it possible that the initial context is somehow invalid or damaged? If so, how would I diagnose the issue?
Howcome you have a different context? And even if you have a different context created for another window, all gl functions should work as usual.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Howcome you have a different context? And even if you have a different context created for another window, all gl functions should work as usual.


I didn't author the application, I'm just trying to make it work. :) Regardless, even with the other context glGetString still crashes...
It will only be invalid if it isn't the current rendering context or has been deleted (Which may happen before rendering to create the other context), it may not work on the second context because that might be a forward compatible one.

Try using glGetStringi.

Of course I have no real idea because there isn't enough information, and this depends on what you are actually doing with the glgetstring!

Engineering Manager at Deloitte Australia


It will only be invalid if it isn't the current rendering context or has been deleted (Which may happen before rendering to create the other context), it may not work on the second context because that might be a forward compatible one.

Try using glGetStringi.

Of course I have no real idea because there isn't enough information, and this depends on what you are actually doing with the glgetstring!


No, you don't need to just guess how GL works. It is well documented in the spec.
glGetString works on forward context.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

[quote name='CRYP7IK' timestamp='1306204627' post='4814850']
It will only be invalid if it isn't the current rendering context or has been deleted (Which may happen before rendering to create the other context), it may not work on the second context because that might be a forward compatible one.

Try using glGetStringi.

Of course I have no real idea because there isn't enough information, and this depends on what you are actually doing with the glgetstring!


No, you don't need to just guess how GL works. It is well documented in the spec.
glGetString works on forward context.
[/quote]

Hey it does too, I guess assumptions are bad.

Engineering Manager at Deloitte Australia

Hmm. Well, glGetStringi may not be available anyway... Any other possibilities?

This topic is closed to new replies.

Advertisement