View Full Version : Checking For Extensions

11-14-2003, 01:40 PM
Whenever I try to check for extensions, my system crashes. I have no idea why. I copied the code word for word from two NeHe examples and OpenGL Game Programming but it still crashes my system. I tried printing out glGetString(GL_EXTENSIONS) but it printed out the last 512 or so characters. My guess is that the string is too large to fit into a char *. But how do I go around that? One of the NeHe examples had malloc() to get the string, but that still didn't work. Does anyone have any ideas? Thank you.

11-14-2003, 02:09 PM
You seem to have a problem with memory buffers and string handling.

glGetString(GL_EXTENSIONS) returns a pointer to a string that can be used and parsed without problems. This usually works well for me:

const GLubyte *extns;
extns = glGetString(GL_EXTENSIONS);

You should be very careful with copying the contents of the returned string, since you can not know beforehand how long it is (many programs has/had bugs because of this - Unreal Tournament is one example).

If you really, really have to make a copy of the returned string (I can't think of a single reason why you would need to do that), use strlen or something to find out how long the string is, and then malloc the necessary memory (strlen+1).