Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: App crashes if more than 1 sprite used  (Read 3734 times)

0 Members and 1 Guest are viewing this topic.

Gouki

  • Newbie
  • *
  • Posts: 4
    • View Profile
App crashes if more than 1 sprite used
« 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 :(

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
App crashes if more than 1 sprite used
« Reply #1 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.

Gouki

  • Newbie
  • *
  • Posts: 4
    • View Profile
App crashes if more than 1 sprite used
« Reply #2 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.

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
App crashes if more than 1 sprite used
« Reply #3 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
App crashes if more than 1 sprite used
« Reply #4 on: August 19, 2009, 08:48:21 am »
Are you mixing release and debug configurations?
Laurent Gomila - SFML developer

Gouki

  • Newbie
  • *
  • Posts: 4
    • View Profile
App crashes if more than 1 sprite used
« Reply #5 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...

Gouki

  • Newbie
  • *
  • Posts: 4
    • View Profile
App crashes if more than 1 sprite used
« Reply #6 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

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
App crashes if more than 1 sprite used
« Reply #7 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.

Devil0150

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
App crashes if more than 1 sprite used
« Reply #8 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.

 

anything