Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 mv348   Members   -  Reputation: 253

Like
0Likes
Like

Posted 21 March 2013 - 07:48 PM

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!

 



Sponsor:

#2 Sponji   Members   -  Reputation: 1355

Like
1Likes
Like

Posted 22 March 2013 - 04:53 AM

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


Derp

#3 mv348   Members   -  Reputation: 253

Like
0Likes
Like

Posted 23 March 2013 - 03:54 PM

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



#4 RobTheBloke   Crossbones+   -  Reputation: 2341

Like
1Likes
Like

Posted 23 March 2013 - 09:44 PM

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



#5 mv348   Members   -  Reputation: 253

Like
0Likes
Like

Posted 24 March 2013 - 11:33 AM

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.



#6 mhagain   Crossbones+   -  Reputation: 8278

Like
0Likes
Like

Posted 24 March 2013 - 01:19 PM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#7 RobTheBloke   Crossbones+   -  Reputation: 2341

Like
0Likes
Like

Posted 24 March 2013 - 02:03 PM

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



#8 mhagain   Crossbones+   -  Reputation: 8278

Like
0Likes
Like

Posted 24 March 2013 - 04:03 PM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#9 mv348   Members   -  Reputation: 253

Like
0Likes
Like

Posted 24 March 2013 - 08:53 PM

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!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS