[Solved] SDL image error?

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
ParticleGames
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 53
Joined: Sat Feb 19, 2011 1:20 pm
Current Project: A map editor for a platformer I plan to develop
Favorite Gaming Platforms: Wii, Gamecube
Programming Language of Choice: C++

[Solved] SDL image error?

Post by ParticleGames »

I am currently in the process of making a SHMUP. I have a background ready to blit, but when I apply the background to the screen, it doesn't show up. I am flipping the screen, in case you were wondering. Also, when I test the image I am trying to use isn't NULL. I am using Code::Blocks on windows vista. My images are pngs and are in a folder titled "SHMUP." Directly inside SHMUP are my images, my project, and a SHMUP.exe file. Also in the SHMUP folder are the "bin" and "obj" folders. Inside bin is Debug, and inside Debug is another SHMUP.exe! There are also other dlls and files of those sort(I am on my iPod I can't completely remember) in bin/Debug. When I put my images in the directory of the other exe (bin/Debug) my program crashes and returns 3. I am so confused, I have done so much googling it's ridiculous. Does anyone think they can help?

Code: Select all

//classes.h (only the code that applies to my problem)
class ImageManager //loads and manages images
{
    private:

    SDL_Surface* playerShip, *miniShip, *medShip, *bigShip; //player and enemy
    SDL_Surface* background;
    SDL_Surface* miniBullet, *medBullet, *bigBullet;

    public:

    ImageManager();
    ~ImageManager();
    SDL_Surface * get_image(imageType type);

};


//classes.cpp (part of code that applies to my error)
ImageManager::ImageManager()
{
    //ships
    playerShip = load_image("playerShip.png");
    miniShip = load_image("miniShip.png");
    medShip = load_image("medShip.png");
    bigShip = load_image("bigShip.png");
    //bullets
    miniBullet = load_image("miniBullet.png");
    medBullet = load_image("medBullet.png");
    bigBullet = load_image("bigBullet.png");
    //other
    background = load_image("background.png");
}

SDL_Surface* ImageManager::get_image(imageType type)
{
    switch(type)
    {
        case EplayerShip:
        return playerShip;
        break;

        case EminiShip:
        return miniShip;
        break;

        case EmedShip:
        return medShip;
        break;

        case EbigShip:
        return bigShip;
        break;

        case Ebackground:
        return background;
        break;

        case EminiBullet:
        return miniBullet;
        break;

        case EmedBullet:
        return medBullet;
        break;

        case EbigBullet:
        return bigBullet;
        break;

        default: break;
    }
    return NULL;
}

ImageManager::~ImageManager()
{
    //ships
    SDL_FreeSurface(playerShip);
    SDL_FreeSurface(miniShip);
    SDL_FreeSurface(medShip);
    SDL_FreeSurface(bigShip);
    //bullets
    SDL_FreeSurface(miniBullet);
    SDL_FreeSurface(medBullet);
    SDL_FreeSurface(bigBullet);
    //other
    SDL_FreeSurface(background);
}




//main.cpp
int SDL_main(int argc, char *argv[])
{
    set_up();

    ImageManager imageMan;
    SDL_Surface * background = imageMan.get_image(Ebackground);

    bool quit = false;

    while(quit==false)
    {
        //background's area
        SDL_Rect backgroundClips;
        backgroundClips.x = 0;
        backgroundClips.y = 0;
        backgroundClips.w = 640;
        backgroundClips.h = 480;

        //banner
        SDL_Rect banner;
        banner.x = 0;
        banner.y = 0;
        banner.w = 640;
        banner.h = 30;

        apply_surface(0,30,background,screen,&backgroundClips);
        SDL_FillRect(screen,&banner,SDL_MapRGB(screen->format,40,60,180));
        SDL_Flip(screen);
        while(SDL_PollEvent(&event))
        {
            if(event.type == SDL_QUIT)
            {
                quit = true;
            }
        }
    }

    clean_up();
    return 0;
}
Last edited by ParticleGames on Sun Mar 06, 2011 8:35 am, edited 3 times in total.
Check out my iPhone app here: http://twilighthop.com
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: SDL image error?

Post by Ginto8 »

a few things:
1) post some code relevant to the issue
2) IIRC, Code::Blocks runs the program from the directory where the project file is, so make sure the file path is correct from that.
3) Image loading and drawing code both seem to be relevant here.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
ParticleGames
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 53
Joined: Sat Feb 19, 2011 1:20 pm
Current Project: A map editor for a platformer I plan to develop
Favorite Gaming Platforms: Wii, Gamecube
Programming Language of Choice: C++

Re: SDL image error?

Post by ParticleGames »

I added code. Also, the .exe that is in the location of the project file crashes when I run it. The other .exe in bin/Debug runs fine, but doesn't blit the images. And what do you mean by "make sure the file path is correct?" What file path?

And I know what's also coming about my code. I will try to implement error handling functions.
Check out my iPhone app here: http://twilighthop.com
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: SDL image error?

Post by N64vSNES »

I've had this issue countless times in the past.

The solution is always:

A- Your path is incorrect and your program can't find it
B- You've not got "libpng.dll" in your executables directory (You'll get no error message and the program will execute but you won't be able to use the SDL_Image library.
User avatar
ParticleGames
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 53
Joined: Sat Feb 19, 2011 1:20 pm
Current Project: A map editor for a platformer I plan to develop
Favorite Gaming Platforms: Wii, Gamecube
Programming Language of Choice: C++

Re: SDL image error?

Post by ParticleGames »

I've tried putting libpng12-0.dll basically everywhere, and it still doesn't work. I also checked to see if my images were NULL, and it appears that they aren't NULL. The build log says:

Checking for existence: ...\SHMUP\SHMUP.exe
Executing: ...\SHMUP\SHMUP.exe (in ...\SHMUP\bin\Debug)
:x :x
Check out my iPhone app here: http://twilighthop.com
User avatar
xiphirx
Chaos Rift Junior
Chaos Rift Junior
Posts: 324
Joined: Mon Mar 22, 2010 3:15 pm
Current Project: ******** (Unkown for the time being)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Contact:

Re: SDL image error?

Post by xiphirx »

You also need SDL_image.dll :P
StarCraft II Zerg Strategy, open to all levels of players!

Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of :)
User avatar
ParticleGames
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 53
Joined: Sat Feb 19, 2011 1:20 pm
Current Project: A map editor for a platformer I plan to develop
Favorite Gaming Platforms: Wii, Gamecube
Programming Language of Choice: C++

Re: SDL image error?

Post by ParticleGames »

That's there too. This is a frustrating error :x
Check out my iPhone app here: http://twilighthop.com
krilik
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 25
Joined: Sat Apr 18, 2009 11:24 pm
Favorite Gaming Platforms: SNES,PS1

Re: SDL image error?

Post by krilik »

I think I've had this problem before, or a similar problem. I ended up putting all my SDL related DLL files in my windows/system32 folder because I was tired of it.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: SDL image error?

Post by dandymcgee »

krilik wrote:I think I've had this problem before, or a similar problem. I ended up putting all my SDL related DLL files in my windows/system32 folder because I was tired of it.
Which works great until you try to redistribute it. ;)
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: SDL image error?

Post by N64vSNES »

Yeah SDL_image.dll is needed but I suggested libpng.dll because if you it will still run fine with it however SDL will refuse to load anything. Whereas with SDL_image.dll you get a pretty obvious error.

It needs to be in the same folder as the .exe you're running, if it still doesn't work you must be giving a incorrect filename.
User avatar
ParticleGames
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 53
Joined: Sat Feb 19, 2011 1:20 pm
Current Project: A map editor for a platformer I plan to develop
Favorite Gaming Platforms: Wii, Gamecube
Programming Language of Choice: C++

Re: SDL image error?

Post by ParticleGames »

I implemented error functions, and in stdout.txt it says:


Couldn't open playerShip.png
Couldn't open miniShip.png
Couldn't open medShip.png
Couldn't open bigShip.png
Couldn't open miniBullet.png
Couldn't open medBullet.png
Couldn't open bigBullet.png
Couldn't open background.png

I am 99% sure my filenames are correct. Could it have to do with the working directories and such? I am confused how those work, so I might be wrong.
Check out my iPhone app here: http://twilighthop.com
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: SDL image error?

Post by Ginto8 »

It's definitely problem of filepath. Your files should be in 1 of 2 places: where your executable is, or where your source files are. If one of them doesn't work, it's almost definitely the other.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
ParticleGames
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 53
Joined: Sat Feb 19, 2011 1:20 pm
Current Project: A map editor for a platformer I plan to develop
Favorite Gaming Platforms: Wii, Gamecube
Programming Language of Choice: C++

Re: SDL image error?

Post by ParticleGames »

Which exe? The one by my project or the one in bin/Debug? Also, my sourcefiles are in the same directory as the first exe.
Check out my iPhone app here: http://twilighthop.com
User avatar
xiphirx
Chaos Rift Junior
Chaos Rift Junior
Posts: 324
Joined: Mon Mar 22, 2010 3:15 pm
Current Project: ******** (Unkown for the time being)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Contact:

Re: SDL image error?

Post by xiphirx »

ParticleGames wrote:Which exe? The one by my project or the one in bin/Debug? Also, my sourcefiles are in the same directory as the first exe.
How about you add simple temp code to create a file, then look for the file. Wherever it is, thats where your sprites go.
StarCraft II Zerg Strategy, open to all levels of players!

Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of :)
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: SDL image error?

Post by N64vSNES »

Sounds like you're having trouble with the way your IDE has set up your folders.

The should be two folders in your project folder "debug" and "release" both will have a executable.

So make sure your *.DLL files and your image files are in that directory (debug or release depending on what mode you're running it in).

Other than that I'm not sure what to suggest.
Post Reply