Skip to content

Commit

Permalink
Properly lock image.
Browse files Browse the repository at this point in the history
  • Loading branch information
Relintai committed Mar 9, 2024
1 parent c67d453 commit 3be690d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions modules/layered_tile_map/layered_tile_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ PoolVector2iArray LayeredTileMapPattern::get_used_cells() const {
a.resize(pattern.size());
PoolVector2iArray::Write w = a.write();
Vector2i *wptr = w.ptr();

int i = 0;

for (const HashMap<Vector2i, LayeredTileMapCell>::Element *E = pattern.front(); E; E = E->next) {
wptr[i++] = E->key();
}
Expand Down Expand Up @@ -2578,6 +2578,7 @@ Vector<Vector<Ref<Texture>>> LayeredTileSet::generate_terrains_icons(Size2i p_si
for (int terrain = 0; terrain < get_terrains_count(terrain_set); terrain++) {
Ref<Image> dst_image;
dst_image.instance();

if (counts[terrain_set][terrain].count > 0) {
// Get the best tile.
Ref<Texture> src_texture = counts[terrain_set][terrain].texture;
Expand All @@ -2592,8 +2593,12 @@ Vector<Vector<Ref<Texture>>> LayeredTileSet::generate_terrains_icons(Size2i p_si
dst_image->resize(p_size.x, p_size.y, Image::INTERPOLATE_NEAREST);
} else {
dst_image->create(1, 1, false, Image::FORMAT_RGBA8);

dst_image->lock();
dst_image->set_pixel(0, 0, get_terrain_color(terrain_set, terrain));
dst_image->unlock();
}

Ref<ImageTexture> icon;
icon.instance();
icon->create_from_image(dst_image);
Expand Down Expand Up @@ -5704,7 +5709,7 @@ Ref<ImageTexture> LayeredTileSetAtlasSource::_create_padded_image_texture(const
Ref<Image> image;
image.instance();
image->create(size.x, size.y, false, src_image->get_format());

src_image->lock();
image->lock();

Expand Down Expand Up @@ -5737,7 +5742,7 @@ Ref<ImageTexture> LayeredTileSetAtlasSource::_create_padded_image_texture(const
image->blit_rect(*src_image, Rect2i(src_rect.position + Vector2i(src_rect.size.x - 1, src_rect.size.y - 1), Vector2i(1, 1)), base_pos + Vector2i(src_rect.size.x, src_rect.size.y));
}
}

image->unlock();
src_image->unlock();

Expand Down

0 comments on commit 3be690d

Please sign in to comment.