Skip to content

Commit

Permalink
Fix crash un-doing creation of layer while hovering over it
Browse files Browse the repository at this point in the history
  • Loading branch information
Vankata453 committed Oct 21, 2024
1 parent 3d5d306 commit 3de0fa8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/editor/layers_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,7 @@ EditorLayersWidget::draw(DrawingContext& context)
void
EditorLayersWidget::update(float dt_sec)
{
auto it = m_layer_icons.begin();
while (it != m_layer_icons.end())
{
auto layer_icon = (*it).get();
if (!layer_icon->is_valid())
{
it = m_layer_icons.erase(it);
continue;
}
++it;
}
remove_invalid_layers();

TileMap* selected_tilemap = get_selected_tilemap();
if (selected_tilemap)
Expand Down Expand Up @@ -460,6 +450,8 @@ EditorLayersWidget::add_layer(GameObject* layer, bool initial)
void
EditorLayersWidget::update_tip()
{
remove_invalid_layers();

if (m_hovered_layer == m_layer_icons.size())
m_object_tip->set_info(_("Add Layer"));
else if (m_hovered_layer > m_layer_icons.size())
Expand All @@ -477,6 +469,22 @@ EditorLayersWidget::update_current_tip()
update_tip();
}

void
EditorLayersWidget::remove_invalid_layers()
{
auto it = m_layer_icons.begin();
while (it != m_layer_icons.end())
{
auto layer_icon = (*it).get();
if (!layer_icon->is_valid())
{
it = m_layer_icons.erase(it);
continue;
}
++it;
}
}

TileMap*
EditorLayersWidget::get_selected_tilemap() const
{
Expand Down
2 changes: 2 additions & 0 deletions src/editor/layers_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ class EditorLayersWidget final : public Widget
private:
Vector get_layer_coords(const int pos) const;
int get_layer_pos(const Vector& coords) const;

void update_tip();
void remove_invalid_layers();

private:
Editor& m_editor;
Expand Down

0 comments on commit 3de0fa8

Please sign in to comment.