Results 1 to 3 of 3

Thread: c++ Corrupt stack ? when function ends ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    UK
    Posts
    127

    c++ Corrupt stack ? when function ends ?

    VB Code:
    1. int LoadSceneTextures(char *fname, int ArraySpace)                                    // Load Bitmaps And Convert To Textures
    2. {
    3.         int Status=FALSE;                               // Status Indicator
    4.  
    5.         AUX_RGBImageRec *TextureImage[1];               // Create Storage Space For The Texture
    6.  
    7.         memset(TextureImage,0,sizeof(void *)*1);        // Set The Pointer To NULL
    8.  
    9.         char OpenThis[256];
    10.         strcat(OpenThis,"Textures/");
    11.         strcat(OpenThis, fname);
    12.  
    13.         // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
    14.         if (TextureImage[0]=LoadBMP(OpenThis))
    15.         {
    16.                 Status=TRUE;                            // Set The Status To TRUE
    17.  
    18.                 glGenTextures(ArraySpace, &SceneTextures[ArraySpace]);          // Create One Texture
    19.                 // Create Linear Filtered Texture
    20.                 glBindTexture(GL_TEXTURE_2D, SceneTextures[ArraySpace]);
    21.                 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    22.                 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    23.                 glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
    24.         }
    25.  
    26.         if (TextureImage[0])                            // If Texture Exists
    27.         {
    28.                 if (TextureImage[0]->data)              // If Texture Image Exists
    29.                 {
    30.                         free(TextureImage[0]->data);    // Free The Texture Image Memory
    31.                 }
    32.  
    33.                 free(TextureImage[0]);                  // Free The Image Structure
    34.         }
    35.         return Status;                                  // Return The Status
    36. }

    im trying to load a texture to a gl array and this keeps returning stack around OpenThis was corrupt ?? how can i stop this from happening ?

    The function seems to work but crashes when its finished ??

    any ideas ?

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    UK
    Posts
    127

    Re: c++ Corrupt stack ? when function ends ?

    replaced this
    VB Code:
    1. char OpenThis[256];
    2.         strcat(OpenThis,"Textures/");
    3.         strcat(OpenThis, fname);


    with this and it now works


    VB Code:
    1. char OpenThis[256];
    2.         strcpy(OpenThis,"");
    3.         strcat(OpenThis,"Textures/");
    4.         strcat(OpenThis, fname);

  3. #3
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048

    Re: c++ Corrupt stack ? when function ends ?

    even better:

    Code:
    char OpenThis[256];
    		strcpy(OpenThis,"Textures/");
    		strcat(OpenThis, fname);

Posting Permissions

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



Click Here to Expand Forum to Full Width