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:
parent
516f20124f
commit
e88179b788
3 changed files with 8 additions and 3 deletions
|
|
@ -30,6 +30,7 @@ namespace guecs {
|
|||
bool stretch = true;
|
||||
bool is_icon = false;
|
||||
std::shared_ptr<sf::Sprite> sprite = nullptr;
|
||||
std::shared_ptr<sf::Texture> texture = nullptr;
|
||||
|
||||
void init(lel::Cell &cell);
|
||||
void update(const string& new_name);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ project('lel-guecs', 'cpp',
|
|||
])
|
||||
|
||||
# use this for common options only for our executables
|
||||
cpp_args=[]
|
||||
cpp_args=[
|
||||
'-Wno-deprecated-declarations'
|
||||
]
|
||||
link_args=[]
|
||||
# these are passed as override_defaults
|
||||
exe_defaults = [ 'warning_level=2' ]
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue