SFML community forums
Help => Graphics => Topic started 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:
#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:
Process returned -1073741819 (0xC0000005)
I get the same message each time.
Any ideas? I'm desperated :(
-
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.
-
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.
-
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?
-
Are you mixing release and debug configurations?
-
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...
-
Okay, just tested something. If I create the images on the heap memory, it works fine:
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
-
What happens if you use a second image (instead of a second "test.png")? Like just some random other image.
-
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.