PDA

View Full Version : OpenGL shaders acting up




tgashby
Feb 13, 2012, 05:48 PM
Hey everyone,

First to get the usual details out of the way:

Late 2008 Macbook Pro
OSX Lion 10.7.3
2.53 GHz Intel Core 2 Duo
4 GB RAM
NVIDIA GeForce 9400M GT 512 MB

I have been working on a graphics project (game) with 5 others.

We are using OpenGL, and SDL to make it.

We just recently demo'ed our progress on my laptop and everything went great.

I have made no changes, not a single character, to the code and now it is segfaulting on a glCreateShader call. It is passed GL_VERTEX_SHADER.

It seems to me that OpenGL has just crapped out all of a sudden and I have no idea why.

I ran it by the nearest Apple Store and they ran the usual hardware diagnostics and didn't find anything they weren't expecting.

I have tried running the code both from XCode 4 and the terminal, both compile successfully and both segfault in the same place.

I think I just recently updated to 10.7.3, so there could be an issue there. I have no idea how to roll back the update, or if it's even possible. (Doesn't seem to be from my quick googling.)

Any thoughts?

Thank you,
Tag Ashby



KnightWRX
Feb 13, 2012, 07:08 PM
Looking online, the only reason I could see for this is that you're trying to create a shader without a properly initialized rendering context. Are you sure your rendering context creation code is still working ?

tgashby
Feb 13, 2012, 07:15 PM
Thanks KnightWRX,

I forgot to mention that the other 5 people can run it just fine.

And yes, I'm sure I have a GL context.

I appreciate the help though :-).

KnightWRX
Feb 13, 2012, 07:41 PM
Are you actively checking that the View's OpenGL Context is valid or are you just assuming ? Have you tried to fetch it and make it current and see if that pops up an error ?

Have you checked the OpenGL Driver Monitor that ships with XCode ? In the monitors menu, you have an entry called Rendering Info which does a lot of glGetString() work for you. Have you checked that the driver is ok and supported GLSL 1.2 ?

tgashby
Feb 13, 2012, 08:08 PM
Driver is fine according to the Renderer Info. Supports GLSL 1.5 or 1.2 in compatability mode.

I am just assuming it's fine, but I just don't see how it's possible that it would run flawlessly for almost 2 months and then stop working.

The code hasn't changed at all since the presentation :-\.

Calling a glGetString will blow up if I put it above the line that is currently blowing up. Looks like the GL context is messed up. I'll have to look into that.

Some issues boggle the mind.

Thank again. I never knew it had an OpenGL monitor!

KnightWRX
Feb 13, 2012, 08:14 PM
Calling a glGetString will blow up if I put it above the line that is currently blowing up. Looks like the GL context is messed up. I'll have to look into that.

Definately sounds like you're not creating a valid rendering context. NSOpenGLView has a -(NSOpenGLContext *) openGLContext method that returns its context. You can make it current with NSOpenGLContext's makeCurrentContext.

Assuming a custom view that inherits from NSOpenGLView :

[[self openGLContext] makeCurrentContext];

NSOpenGLContext also has a class method to retrieve the current context, [NSOpenGLContext currentContext] which will return nil if no context exists. You should definitely check that one out.

tgashby
Feb 13, 2012, 08:28 PM
I will check that out.

What is troubling is that I shouldn't need to worry about creating a context.

We are using SDL which is supposed to be making the context for us...

Well, no idea what I really did... Changed a few SDL flags and for the time being it work again... hopefully for good.

Thank you so much for your help!

P.S. I have tried setting it as "Resolved" but I'm not seeing that option anywhere...

KnightWRX
Feb 13, 2012, 08:32 PM
Ugh, right, it's there in the first post too that you're using SDL. I don't know how SDL does the context creation or anything, it seems it's all done in SDL_SetVideoMode();

Edit : version control repositories FTW :

http://hg.libsdl.org/SDL/file/d69f2aa6f048/src/video/cocoa/SDL_cocoaopengl.m

Seems it's using Apple's NSOpenGLContext and its related functions. Looks to me like this is a big hint on what to do :

147 context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
148
149 [fmt release];
150
151 if (context == nil) {
152 SDL_SetError ("Failed creating OpenGL context");
153 [pool release];
154 return NULL;
155 }

Have you tried calling SDL_GetError() to see if its failing at creating the context ? Your attributes were probably causing some unsupported flags to be set in the pixelformat.

tgashby
Feb 13, 2012, 08:36 PM
Ugh, right, it's there in the first post too that you're using SDL. I don't know how SDL does the context creation or anything, it seems it's all done in SDL_SetVideoMode();

Haha no need to worry.

I'm pretty comfortable with SDL, but sometimes it throws me for a loop. You are right, everything is done in SetVideoMode.

KnightWRX
Feb 13, 2012, 08:44 PM
look at my edit.

tgashby
Feb 13, 2012, 08:47 PM
Ah!

Thank you!

Still doesn't explain why it stopped all of a sudden.... but I'll take it!

If it ever happens again I know what to do!