Hello, I use the SVN revision 1691 of SFML 2 and I compile with Visual Studio 2010. I just encountered a very strange behaviour. Given the following code, a blue sprite is drawn as expected:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow app(sf::VideoMode(200, 200), "Title");
app.SetFramerateLimit(30);
sf::Image image;
image.Create(30, 30, sf::Color::Blue);
for (;;)
{
sf::Event event;
while (app.GetEvent(event))
{
if (event.Type == sf::Event::KeyPressed)
return 0;
}
app.Clear();
sf::Sprite sprite(image);
app.Draw(sprite);
app.Display();
}
}
Now let's declare the sf::Image locally inside the loop (which may be inefficient, but not fundamentally wrong), like this:#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow app(sf::VideoMode(200, 200), "Title");
app.SetFramerateLimit(30);
for (;;)
{
sf::Event event;
while (app.GetEvent(event))
{
if (event.Type == sf::Event::KeyPressed)
return 0;
}
app.Clear();
sf::Image image;
image.Create(30, 30, sf::Color::Blue);
sf::Sprite sprite(image);
app.Draw(sprite);
app.Display();
}
}
And what I get is a white sprite. :shock:
Actually, by observing it more precisely, I see it blue for a single frame (the first one), then it becomes white for the rest of the time.
I'm confused because the image is still in scope when the sprite is drawn. Must it exist any longer?