Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: Truncated GL_EXTENSIONS String

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2000
    Posts
    11

    Truncated GL_EXTENSIONS String

    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?

  2. #2

    Re: Truncated GL_EXTENSIONS String

    Strange..

    Have you tried doing a strncpy into a buffer?

    char ext[2048];
    strncpy( buf, (const char*)glGetString(GL_EXTENSIONS),sizeof(ext)-1);

  3. #3

    Re: Truncated GL_EXTENSIONS String

    Originally posted by fresh:
    Strange..

    Have you tried doing a strncpy into a buffer?

    char ext[2048];
    strncpy( ext, (const char*)glGetString(GL_EXTENSIONS),sizeof(ext)-1);


  4. #4
    Junior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    247

    Re: Truncated GL_EXTENSIONS String

    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?

  5. #5
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,444

    Re: Truncated GL_EXTENSIONS String

    Originally posted by fresh:
    Strange..

    Have you tried doing a strncpy into a buffer?

    char ext[2048];
    strncpy( buf, (const char*)glGetString(GL_EXTENSIONS),sizeof(ext)-1);

    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.

  6. #6
    Junior Member Newbie
    Join Date
    Nov 2000
    Posts
    11

    Re: Truncated GL_EXTENSIONS String

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

  7. #7
    Junior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    247

    Re: Truncated GL_EXTENSIONS String

    FYI:
    sizeof(ext)-1 = sizeof(char *)-1 = 3 (on a 32-bit system), when ext is declared as:
    char ext[2048];

  8. #8
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,444

    Re: Truncated GL_EXTENSIONS String

    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.

  9. #9
    Junior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    247

    Re: Truncated GL_EXTENSIONS String

    You're absolutely right! Sorry.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •