Small mistake. Didn't maintain the texture pointer in the sprite so it could go out of scope and crash with use after free.

This commit is contained in:
Zed A. Shaw 2026-03-11 07:39:50 -04:00
parent 516f20124f
commit e88179b788
3 changed files with 8 additions and 3 deletions

View file

@ -59,7 +59,8 @@ namespace guecs {
if(new_name != name) {
name = new_name;
auto sprite_texture = BACKEND->get_sprite(name);
sprite->setTexture(*sprite_texture.texture);
texture = sprite_texture.texture;
sprite->setTexture(*texture);
sprite->setTextureRect({{0,0},sprite_texture.frame_size});
}
}
@ -71,7 +72,8 @@ namespace guecs {
auto bounds = sprite_texture.frame_size;
sf::IntRect rect{{0,0}, bounds};
sprite = make_shared<sf::Sprite>(*sprite_texture.texture, rect);
texture = sprite_texture.texture;
sprite = make_shared<sf::Sprite>(*texture, rect);
if(stretch) {
sprite->setScale({