Jump to content
  • Advertisement
Sign in to follow this  
mv348

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

This topic is 1944 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

 

Share this post


Link to post
Share on other sites
Advertisement

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.. :(

Share this post


Link to post
Share on other sites

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?)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!