SFML community forums

Help => Graphics => Topic started by: Gouki on August 19, 2009, 03:13:47 am

Title: App crashes if more than 1 sprite used
Post by: Gouki on August 19, 2009, 03:13:47 am
Hey guys.

I have no idea what's going wrong here. This is the problem:

Code: [Select]
#include <SFML/Graphics.hpp>

using namespace sf;

int main()
{
    RenderWindow App(VideoMode(800,600,32), "Test", Style::Titlebar);
    App.Clear(Color(255,255,255));

    Image i_one;
    if( !i_one.LoadFromFile("test.png") )
        return EXIT_FAILURE;
    Sprite s_one(i_one);

    Image i_two;
    if( !i_two.LoadFromFile("test.png") )
        return EXIT_FAILURE;
    Sprite s_two(i_two);

    App.Draw(s_one);
    App.Draw(s_two);
    App.Display();
    Sleep(1.0f);
    App.Close();

    return EXIT_SUCCESS;
}


This code causes my application to crash. If I only declare one sprite, everything works fine. But from the moment I use two or more sprites the application crashes and it can't be helped. The message I receive is as follows:

Quote
Process returned -1073741819 (0xC0000005)


I get the same message each time.

Any ideas? I'm desperated :(
Title: App crashes if more than 1 sprite used
Post by: Astrof on August 19, 2009, 03:20:54 am
what do you mean "crash?" you have no event loop and thus it only draws once then closes.  Though that doesn't explain the process return or anything.
Title: App crashes if more than 1 sprite used
Post by: Gouki on August 19, 2009, 03:49:13 am
I just broke down the code to its absolute minimum. Even if I have an event loop this message occurs. If I quit my application while only one sprite is being used, the application returns the value 0x0, everything fine. If I use more than one sprite, it returns 0xC0000005 on closure.
Title: App crashes if more than 1 sprite used
Post by: Astrof on August 19, 2009, 04:34:01 am
What happens if s_two uses the image from i_one?  Have you tried running it in debug mode?  The return code is an access violation error (so means illegal access of memory, probably the image not loading properly (but not returning that it didnt load properly?)).  Have you tried using SetImage() (instead of passing it to the constructor)?

Also, Version of SFML/OS?
Title: App crashes if more than 1 sprite used
Post by: Laurent on August 19, 2009, 08:48:21 am
Are you mixing release and debug configurations?
Title: App crashes if more than 1 sprite used
Post by: Gouki on August 19, 2009, 12:58:54 pm
It happens all in debug mode (yes, I've linked to the proper libs).

SetImage() causes the same effect.

I use SFML 1.5 under WinXP Prof SP3.


Interestingly enough, this doesn't seem to happen if s_two gets its image from i_one Oo Don't understand why...
Title: App crashes if more than 1 sprite used
Post by: Gouki on August 19, 2009, 01:07:04 pm
Okay, just tested something. If I create the images on the heap memory, it works fine:

Code: [Select]
Image *i_one = new Image;
    if( !(*i_one).LoadFromFile("test.png") )
        return EXIT_FAILURE;
    Sprite s_one(*i_one);

    Image *i_two = new Image;
    if( !(*i_two).LoadFromFile("test.png") )
        return EXIT_FAILURE;
    Sprite s_two(*i_two);


Now I am totally confused x_x
Title: App crashes if more than 1 sprite used
Post by: Astrof on August 21, 2009, 06:38:25 am
What happens if you use a second image (instead of a second "test.png")?  Like just some random other image.
Title: App crashes if more than 1 sprite used
Post by: Devil0150 on August 27, 2009, 04:26:06 pm
That code works on me. I get a lot of first chance exceptions but the window still shows. I'm using winxp prof sp3 too, and Visual C++ 2008.