Implement critical fixes for tile cache issues and optimize resource management

- Updated Tile16Editor to regenerate blockset atlas directly from ROM data, bypassing problematic tile cache.
- Enhanced clipboard functionality to extract tile data directly from the atlas, improving reliability.
- Refactored Arena class shutdown process to ensure safe cleanup of resources, preventing double-free issues.
- Optimized Canvas rendering logic to utilize pre-calculated values for improved performance with large selections.
This commit is contained in:
scawful
2025-09-29 09:42:06 -04:00
parent 94f5c0ec60
commit 690f77eea0
3 changed files with 66 additions and 64 deletions

View File

@@ -18,22 +18,8 @@ Arena::Arena() {
}
Arena::~Arena() {
// Safely clear all resources with proper error checking
for (auto& [key, texture] : textures_) {
// Don't rely on unique_ptr deleter during shutdown - manually manage
if (texture && key) {
[[maybe_unused]] auto* released = texture.release(); // Release ownership to prevent double deletion
}
}
textures_.clear();
for (auto& [key, surface] : surfaces_) {
// Don't rely on unique_ptr deleter during shutdown - manually manage
if (surface && key) {
[[maybe_unused]] auto* released = surface.release(); // Release ownership to prevent double deletion
}
}
surfaces_.clear();
// Use the safe shutdown method that handles cleanup properly
Shutdown();
}
/**
@@ -102,13 +88,22 @@ void Arena::FreeTexture(SDL_Texture* texture) {
}
void Arena::Shutdown() {
// Clear all resources safely - let the unique_ptr deleters handle the cleanup
// while SDL context is still available
// Process any remaining batch updates before shutdown
ProcessBatchTextureUpdates();
// Just clear the containers - the unique_ptr destructors will handle SDL cleanup
// This avoids double-free issues from manual destruction
// Clear pool references first to prevent reuse during shutdown
surface_pool_.available_surfaces_.clear();
surface_pool_.surface_info_.clear();
texture_pool_.available_textures_.clear();
texture_pool_.texture_sizes_.clear();
// CRITICAL FIX: Clear containers in reverse order to prevent cleanup issues
// This ensures that dependent resources are freed before their dependencies
textures_.clear();
surfaces_.clear();
// Clear any remaining queue items
batch_update_queue_.clear();
}
/**