This is a strange one…
I’m attempting to read the extension string in with:
char *pString;
pString = (char *)glGetString(GL_EXTENSIONS);
This has worked flawlessly in the past, now it gets a string that’s truncated at about 240 characters, with no \0 on the end to terminate the string.
I’m using the latest OpenGL 1.4, included in the NVidia 40.41 drivers.
Any ideas?
Strange…
Have you tried doing a strncpy into a buffer?
char ext[2048];
strncpy( buf, (const char*)glGetString(GL_EXTENSIONS),sizeof(ext)-1);
_Aaron
September 19, 2002, 12:42pm
4
This has worked flawlessly in the past, now it gets a string that’s truncated at about 240 characters, with no \0 on the end to terminate the string.
Maybe I’m missing something here, but how is it “truncated” if there’s no ‘\0’ at the end? Is there just random nonsense after 240 characters?
Humus
September 19, 2002, 2:51pm
5
Originally posted by fresh:
[b]Strange…
Have you tried doing a strncpy into a buffer?
char ext[2048];
strncpy( buf, (const char*)glGetString(GL_EXTENSIONS),sizeof(ext)-1);
[/b]
I wouldn’t recommend doing that. The buffer may be too small, or you might read far beyond the end of the end of the string and cause a crash.
Well, turns out it works fine. Thanks for the tips, though… you guys got me thinking “outside the box”. I took another look and realized that the problem had to be in my code. Sure enough…
_Aaron
September 20, 2002, 4:19am
7
FYI:
sizeof(ext)-1 = sizeof(char *)-1 = 3 (on a 32-bit system), when ext is declared as:
char ext[2048];
Humus
September 20, 2002, 4:55am
8
sizeof(ext) returns 2048. It’s an array, not a pointer. Arrays and pointer have lots of similarities, but this is a time where there is a clear difference.
_Aaron
September 20, 2002, 7:39am
9
You’re absolutely right! Sorry.