Results 1 to 2 of 2

Thread: Can't figure out why this is crashing

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2009
    Posts
    7

    Can't figure out why this is crashing

    bool loadPlayerImages(const char* dir, const char* ext, int num_sprites)
    {

    for (i=0;i<=num_sprites;i+=1)
    {

    using namespace std;
    string file = ToString( dir ) + ToString( i ) + ToString( ext );
    const char* pszConstString = file.c_str ();
    MessageBox(0, pszConstString, "ERROR", MB_OK);
    player_image[i] = SOIL_load_OGL_texture
    (
    pszConstString,
    SOIL_LOAD_AUTO,
    SOIL_CREATE_NEW_ID,
    SOIL_FLAG_MIPMAPS | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
    );
    glGetTexLevelParameteriv(GL_TEXTURE_2D, miplevel, GL_TEXTURE_WIDTH, &amp;width[i]);
    glGetTexLevelParameteriv(GL_TEXTURE_2D, miplevel, GL_TEXTURE_HEIGHT, &amp;height[i]);
    };

    }

    Its suppose to take dir, i, and ext and add them together to get a const char* string thats looks like this:

    img/1.bmp


    For some reason it crashes the program. What am I doing wrong?

    Thanks,



    ~Justin123

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    9

    Re: Can't figure out why this is crashing

    Hi,

    Are you getting the desired output from pszConstString? If not try replacing:

    string file = ToString( dir ) + ToString( i ) + ToString( ext );

    with:

    string file;
    char* temp;
    file+=dir;
    sprintf(temp,"%i",i);
    file+=temp;
    file+=ext;

    Also, is the variable i globally declared? You don't declare it in the function (does your compiler allow this?)

    Finally, your for loop goes from 0 to num_sprites, so it actually evaluates everything num_sprites+1 times. Do you actually have num_sprites+1 files to open? (no insult intended here, I've made this mistake many times.)

    Hope this is helpful,
    David

Similar Threads

  1. Trying to figure our glOrtho
    By tr1234586 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-14-2010, 10:43 PM
  2. Who can help me figure this our? thx
    By koalacui in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-04-2005, 07:56 PM
  3. using more than one figure
    By Ziggurat in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-27-2002, 12:35 AM
  4. human figure
    By yaksha in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 07-09-2000, 04:09 AM
  5. Human Figure
    By yaksha in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 07-05-2000, 01:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean