diff --git a/src/app/editor/overworld/overworld_editor.cc b/src/app/editor/overworld/overworld_editor.cc index 1e795ed7..5e432272 100644 --- a/src/app/editor/overworld/overworld_editor.cc +++ b/src/app/editor/overworld/overworld_editor.cc @@ -844,8 +844,11 @@ void OverworldEditor::CheckForSelectRectangle() { } } // Create a composite image of all the tile16s selected - if (!tile16_ids.empty()) { - ow_map_canvas_.DrawBitmapGroup(tile16_ids, tile16_blockset_, 0x10, ow_map_canvas_.global_scale()); + if (!tile16_ids.empty() && map_blockset_loaded_) { + // Ensure the tilemap is ready before drawing + if (tile16_blockset_.atlas.is_active()) { + ow_map_canvas_.DrawBitmapGroup(tile16_ids, tile16_blockset_, 0x10, ow_map_canvas_.global_scale()); + } } } @@ -1008,6 +1011,15 @@ absl::Status OverworldEditor::CheckForCurrentMap() { ImGui::IsMouseClicked(ImGuiMouseButton_Right)) { RefreshOverworldMap(); RETURN_IF_ERROR(RefreshTile16Blockset()); + + // Ensure tile16 blockset is fully updated before rendering + if (tile16_blockset_.atlas.is_active()) { + Renderer::Get().UpdateBitmap(&tile16_blockset_.atlas); + + // Clear any cached tile bitmaps to force re-rendering + tile16_blockset_.tile_bitmaps.clear(); + } + Renderer::Get().UpdateBitmap(&maps_bmp_[current_map_]); maps_bmp_[current_map_].set_modified(false); } diff --git a/src/app/gui/canvas.cc b/src/app/gui/canvas.cc index d9550f99..2caa27ce 100644 --- a/src/app/gui/canvas.cc +++ b/src/app/gui/canvas.cc @@ -745,6 +745,20 @@ void Canvas::DrawBitmapGroup(std::vector &group, gfx::Tilemap &tilemap, return; } + // Pre-render all tiles to avoid timing issues + auto tilemap_size = tilemap.atlas.width() * tilemap.atlas.height() / tilemap.map_size.x; + for (int tile_id : group) { + if (tile_id >= 0 && tile_id < tilemap_size) { + gfx::RenderTile(tilemap, tile_id); + + // Ensure the tile is actually rendered and active + auto tile_it = tilemap.tile_bitmaps.find(tile_id); + if (tile_it != tilemap.tile_bitmaps.end() && !tile_it->second.is_active()) { + core::Renderer::Get().RenderBitmap(&tile_it->second); + } + } + } + // Top-left and bottom-right corners of the rectangle ImVec2 rect_top_left = selected_points_[0]; ImVec2 rect_bottom_right = selected_points_[1]; @@ -789,8 +803,21 @@ void Canvas::DrawBitmapGroup(std::vector &group, gfx::Tilemap &tilemap, // Draw the tile bitmap at the calculated position gfx::RenderTile(tilemap, tile_id); - if (tilemap.tile_bitmaps.find(tile_id) != tilemap.tile_bitmaps.end()) { - DrawBitmap(tilemap.tile_bitmaps[tile_id], tile_pos_x, tile_pos_y, scale, 150); + + // Ensure the tile bitmap exists and is properly rendered + auto tile_it = tilemap.tile_bitmaps.find(tile_id); + if (tile_it != tilemap.tile_bitmaps.end()) { + auto& tile_bitmap = tile_it->second; + // Ensure the bitmap is active before drawing + if (tile_bitmap.is_active()) { + DrawBitmap(tile_bitmap, tile_pos_x, tile_pos_y, scale, 150); + } else { + // Force render if not active + core::Renderer::Get().RenderBitmap(&tile_bitmap); + if (tile_bitmap.is_active()) { + DrawBitmap(tile_bitmap, tile_pos_x, tile_pos_y, scale, 150); + } + } } } i++;