Filelist/filesystem problems -- Null pointer

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
HighBuddha
Posts: 11
Joined: Thu Jun 15, 2006 12:46 am

Filelist/filesystem problems -- Null pointer

Post by HighBuddha »

Hi, I have a method setup in my project that loads bmps using the irrlicht io system and I am having some touble.

Code: Select all

bool CPlayer::loadSprites(video::IVideoDriver* driver, IrrlichtDevice* device)
{
    if(device == NULL)
    {
              return false;
    }
    if(driver == NULL)
    {
              return false;
    }
     
    io::IFileSystem* filesystem = device->getFileSystem();
    if(filesystem == NULL)
    {
                  return false;
    }
    if(!filesystem->changeWorkingDirectoryTo("PLAYER"))
    {
                  return false;
    }
    io::IFileList* filelist = filesystem->createFileList();
    if(filelist == NULL)
    {
                return false;
    }
    
    if(filelist->getFileCount() == 0)
    {
     return false;
    }
    else
    {
        for(int i = 2; i < filelist->getFileCount() - 2; i++)
        {
                c8 filename[MAX_PATH] = "";
                strcpy(filename, filelist->getFileName(i));
                if(strstr(filename, "up"))
                {
                 c8 name[12] = "";
                 strcpy(name, filelist->getFileName(i));
                 sprite_sheet[0]->setname(name);                                    
                 sprite_sheet[0]->setSprite(driver->getTexture(sprite_sheet[0]->getname()));
                }
                else if(strstr(filename, "down"))
                {
                 c8 name[12] = "";
                 strcpy(name, filelist->getFileName(i));
                 sprite_sheet[1]->setname(name);                                    
                 sprite_sheet[1]->setSprite(driver->getTexture(sprite_sheet[1]->getname()));
                }
                else if(strstr(filename, "left"))
                {
                 c8 name[12] = "";
                 strcpy(name, filelist->getFileName(i));
                 sprite_sheet[2]->setname(name);
                 sprite_sheet[2]->setSprite(driver->getTexture(sprite_sheet[2]->getname()));
                }
                else if(strstr(filename, "right"))
                {
                 c8 name[12] = "";
                 strcpy(name, filelist->getFileName(i));
                 sprite_sheet[3]->setname(name);                                    
                 sprite_sheet[3]->setSprite(driver->getTexture(sprite_sheet[3]->getname()));
                }
        }
     filelist->drop();
     return true;
    }
    return false;
}
The method goes through a folder called PLAYER, which holds all the player's bmp files and loads them into CSprite objects.

The problem is at this line:

Code: Select all

io::IFileList* filelist = filesystem->createFileList();
    if(filelist == NULL)
    {
                return false;
    }
The method terminates because of a null pointer, but I dont understand why. From what i can see there shouldn't be any problems (but then again I'm dumb, so thats why I'm asking)

I am using DevCpp and irrlicht 1.2. The only other lib file besides the irrlicht files is libwinmm.a, if thats any help. If any other information is required please let me know.

I am very confused and frustrated so any help would be greatly appreciated.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

I have no problems with this code !!!
I created a folder named "PLAYER" and I get no NULL pointer (at least not at this point) !!!
Maybe your folder structure is wrong ???
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
HighBuddha
Posts: 11
Joined: Thu Jun 15, 2006 12:46 am

Post by HighBuddha »

well i have all my project files in one folder, and the player folder is inside that. I don't have any other folders besides the two. Is there any other possible reason why this would be happening? Or any other information that would help to solve this?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

hmmm, did you try to start the program direct in the folder (dobleclick on exe file) and not inside DevCpp ???
Maybe the working directory of DevCpp is wrong...

I'm using Code::Blocks (I suggest you to switch to it, too - it's much better than Dev and also free) and there you can specify the working directory...

If you want to give C::B a try you can find links and tutorials for installing and setup for use it with Irrlicht on my homepage... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
HighBuddha
Posts: 11
Joined: Thu Jun 15, 2006 12:46 am

Post by HighBuddha »

Ok, thank's for the advice. I'll try that out and edit my post if i have any further questions.
Post Reply