[Resolved] called glewInit() but glCreateProgram() still crashes my application

Started by
7 comments, last by mv348 11 years ago

Dealing with a curious issue.

I have three projects in Visual Studio (each in separate solutions)

1. glfx0.70 (an OpenGL shader creation library available here. It compiles to a static library 'glfx.lib')

2. my project (a fairly sophisticated game engine).

3. a tutorial project (a barebone opengl application that draws a triangle, that I got here )

My objective is to get the glfx functions working in my project. What I've observed is that if I call glCreateProgram() from within my project, it works fine. But if I call a glfx function which in turn calls glCreateProgram, it crashes instantly.

However, if I call glfx from within the tutorial project, no crashing occurs. I understand forgetting glewInit() is usually is the culprit here, but it has been called in my application prior to invoking any functions from glfx. Its as if the static library, glfx.lib is connected to a separate instance of glew that hasn't been initialized. However, adding 'glewInit()' inside the glfx code doesn't fix the problem either.

Any advice or ideas would be appreciated.

Thanks!

Advertisement

Are you sure that the OpenGL context is created before calling glewInit?

Derp

Yes I'm sure!

After checking for consistency in the library references, I noticed that some of the header/library files referenced were different versions of glew. So I made sure they all point to the same thing.

At this point, here's what happens!

I put a message box right before glewInit() in my application to make sure it is called first. It is indeed being called before the error occurs.

If I put glewInit() inside the first function call of glfx, the program doesn't crash. So somehow calling glewInit in my application is not influencing the glew instance of glfx.

Still don't exactly know how to resolve this though.. :(

you are absolutely sure you've created a window with a GL context before calling glewInit? (and that the context has been set to current?)

Yes!

As I said, I can directly call glCreateProgram from within my application, and it works fine. But if (at the exact same location) I call a function from the glfx library, which in turn calls GlCreateProgram,it crashes. However! If I call glewInit() a second time, within glfx, it doesn't crash.

I think its clear that this has something to do with how glew is being linked between my application and the glfx library.

The only explanation for this is that glfx is using it's own, separate, GL context. From a quick parse over the glfx source this isn't something it normally does (it does create one in it's main function, but it seems that's only if it's compiled as a standalone application rather than as a lib, see http://code.google.com/p/glfx/source/browse/trunk/src/glfxc.cpp).

Based on that I'm pointing my finger at you either compiling glfx incorrectly or linking glfx incorrectly to your main program. I'd advise that you use your debugger here; set a breakpoint at your first glfx call and step through line-by-line to see what it's doing. You should very quickly find your culprit.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

are you sure your graphics card actually supports shaders, and have you installed the correct drivers (not falling back on the default driver?).

are you sure your graphics card actually supports shaders, and have you installed the correct drivers (not falling back on the default driver?).

I'd say "yes" to this on account of:

What I've observed is that if I call glCreateProgram() from within my project, it works fine.

That leads me to suspect that a second GL context is being created, which - from looking at the glfx code - leads me to suspect that the OP has messed-up the inclusion of glfx in his main project somehow.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Issue resolved!

There were two reasons. First, there was a hidden, older version of "glew.h" that was removed from my visual studio project, but still sitting inside the project folders. So when i called #include "glew.h" it was opening this hidden file.

Second, I needed to add 'GLEW_STATIC' to my pre-processor definitions. (GLEW_STATIC is already added to the glfx project) I guess this makes sure the gl context is linked together at compile time and not kept separate.

This fixed my problem. I appreciate everyone's suggestions and advice!

This topic is closed to new replies.

Advertisement