Page 1 of 1

Filelist/filesystem problems -- Null pointer

Posted: Sat Feb 17, 2007 7:36 pm
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.

Posted: Sat Feb 17, 2007 8:45 pm
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 ???

Posted: Sat Feb 17, 2007 9:21 pm
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?

Posted: Sat Feb 17, 2007 11:56 pm
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... ;)

Posted: Sun Feb 18, 2007 2:30 am
by HighBuddha
Ok, thank's for the advice. I'll try that out and edit my post if i have any further questions.