Hello, I'm having trouble with a RenderTexture. It seems that in a program where an unrelated RenderWindow has been closed, during the last iteration of the game loop, the RenderTexture gets drawn incorrectly and essentially has nothing on it except for the color used in clear().
I narrowed it down to this piece of code, which draws a simple circle on a green RenderTexture. After the close button has been pressed, The program captures the texture 5 times at different points. On my machine, captures 1 and 2 have the circle, while 3-5 are just green with no graphics.
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
sf::CircleShape shape(200);
shape.setPosition(150, 150);
// Create a new render-texture
sf::RenderTexture texture;
if (!texture.create(500, 500))
return -1;
// The main loop
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
texture.getTexture().copyToImage().saveToFile("test1.png");
window.close();
texture.getTexture().copyToImage().saveToFile("test2.png");
}
}
// Clear the whole texture with green color
texture.clear(sf::Color::Green);
// Draw stuff to the texture
texture.draw(shape); // shape is a sf::Shape
// We're done drawing to the texture
texture.display();
if (!window.isOpen()) texture.getTexture().copyToImage().saveToFile("test3.png");
// Now we start rendering to the window, clear it first
window.clear();
// Draw the texture
sf::Sprite sprite(texture.getTexture());
if (!window.isOpen()) texture.getTexture().copyToImage().saveToFile("test4.png");
window.draw(sprite);
// End the current frame and display its contents on screen
window.display();
if (!window.isOpen()) texture.getTexture().copyToImage().saveToFile("test5.png");
}
}
Is there something I'm doing wrong? Is this a bug in SFML? Thanks.
My specs are: SFML 2.5.1, Windows 10 update 2004, Nvidia graphics with latest drivers. Tested on two machines with similar results.