Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: glTexImage2D

  1. #1
    Intern Contributor
    Join Date
    Jun 2002
    Location
    grenoble, france
    Posts
    94

    glTexImage2D

    hello,

    i have a strange bug regarding glTexImage2D,
    when i call it this way:

    glTexImage2D( GL_TEXTURE_2D, 0, 4, sx, sy, 0, GL_RGBA, GL_UNSIGNED_BYTE, data );

    it's an access violation error. data is a pointer to an array of sx*sy*4 bytes.

    on the call, data is 0x00190958. the call crashes on this instruction,

    0x04F54FEB mov eax,dword ptr [esi]

    as ESI=0x00191000. this is the thing i find strange.

    the context of the call is a bit special too. i use win32. data was allocated with my own malloc. I compiled using /nodefaultlibs, which was made in order to save a few kilobytes on the executable size as i'm working on a project like this one:
    http://www.theproduct.de

    i use a nVidia geForce3 ti 500 under winxp with detonator 29.42.

    anyone could help?
    thank you in advance,

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    May 2001
    Location
    France
    Posts
    765

    Re: glTexImage2D

    Make sure your OpenGL context is initialized when you call glTexImage2D.

    Also, I don't what kind of allocation you do, but to be honest I wouldn't allocate memory manually for the sake of stability. Anyway I agree it's probably a necessity to save those kilobytes for a 64k demo.

    If I were you I would use an assembler which will save even more bytes, but obviously is even more harder to develop with.

  3. #3
    Intern Contributor
    Join Date
    Jun 2002
    Location
    grenoble, france
    Posts
    94

    Re: glTexImage2D

    hi,

    the rendering contexts are correctly initialized. i initialized a pbuffer and a main window rendering context. the main rendering context is active when initialisation is performed.

    it's true that using assembler would probably help saving even more space, but the amount of work to make with assembler is so huge that i'd probably never accomplish anything with it.

    btw, i implemented the math routines and basic C functions in asm already (sin/cos/sqrt/tan/sinf/cosf/sqrtf/memcpy/memset/strlen/rand/srand...).

    regards,

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    May 2001
    Location
    France
    Posts
    765

    Re: glTexImage2D

    ok, what are your sx and sy values when it crashes ?

  5. #5
    Member Regular Contributor
    Join Date
    May 2000
    Posts
    420

    Re: glTexImage2D

    Im pretty sure that data isnt allocated as large as you think it is. You say it is, but lots of times I think something is working a certain way but it isnt. The fact that you say you are using your own version of malloc makes this 1000 times more suspicous. Perhaps a bug in your alloc routine is allocating a few bytes short?
    Ron Frazier

  6. #6
    Junior Member Regular Contributor
    Join Date
    Jun 2000
    Location
    Cambridge, England
    Posts
    190

    Re: glTexImage2D

    Try using the standard malloc. If that works, you know where the problem is.

  7. #7
    Intern Contributor
    Join Date
    Jun 2002
    Location
    grenoble, france
    Posts
    94

    Re: glTexImage2D

    ok, the bug was exterminated

    in fact, the funniest was that it had nothing to do (in appearance) with memory allocation or opengl. the crash came from the fact i used a return (*this); in my class operator implementation. the operators were used during the texture generation process just before sending the texture to the video board memory via glTexImage2D.

    i wonder another thing. can i assume that the pointer to the pixel data won't be used after the call to glTexImage2D by the opengl thread? (in order to free system memory just after uploading textures). currently it seems to work.

    anyway, you're right to be suspicisous about my memory allocation routines . Now the program still crashes in the end during a call to free() ... but it's another story.

    thank you all for replying and helping me.

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,982

    Re: glTexImage2D

    Once the texture is uploaded, you can safely delete your own copy.

  9. #9
    Advanced Member Frequent Contributor
    Join Date
    May 2001
    Location
    France
    Posts
    765

    Re: glTexImage2D

    Right. BUT you have to be ABSOLUTELY SURE that the texture is uploaded. That is, when you call glTexImage2D, you have no guarantee that the operation is executed and terminated at the end of the function. Performance may force some implementations to treat the pointer a few microseconds later (an eternity for todays processors). I wouldn't free the pointer before calling glFlush or glFinish.

  10. #10
    Member Regular Contributor
    Join Date
    May 2000
    Posts
    420

    Re: glTexImage2D

    I dont think you are correct on that. I believe that after the function returns, the pointer is gauranteed to not be used again.
    Ron Frazier

Posting Permissions

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