Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(resource): keep texture metadata across an evictable release

esenginee0cb419d75c7
diff --git a/src/esengine/resource/ResourceManager.cpp b/src/esengine/resource/ResourceManager.cpp
index 4e812309d..c64942531 100644
--- a/src/esengine/resource/ResourceManager.cpp
+++ b/src/esengine/resource/ResourceManager.cpp
@@ -216,18 +216,22 @@ const Texture* ResourceManager::getTexture(TextureHandle handle) const {
}
void ResourceManager::releaseTexture(TextureHandle handle) {
- if (handle.isValid()) {
- if (textures_.getRefCount(handle) == 1) {
- textureMetadata_.erase(handle.id());
- for (auto it = guidToTexture_.begin(); it != guidToTexture_.end(); ) {
- if (it->second == handle) {
- it = guidToTexture_.erase(it);
- } else {
- ++it;
- }
+ if (!handle.isValid()) return;
+ const bool lastRef = textures_.getRefCount(handle) == 1;
+ textures_.release(handle.id());
+ // Drop the sidecar metadata + GUID mapping only when the texture is TRULY gone.
+ // Under an eviction budget the last release keeps it resident and revivable
+ // (findByPath + addRef re-holds the SAME handle), so erasing here would strand
+ // a revived texture without its nine-slice metadata / GUID lookup.
+ if (lastRef && !textures_.isEvictable(handle)) {
+ textureMetadata_.erase(handle.id());
+ for (auto it = guidToTexture_.begin(); it != guidToTexture_.end(); ) {
+ if (it->second == handle) {
+ it = guidToTexture_.erase(it);
+ } else {
+ ++it;
}
}
- textures_.release(handle.id());
}
}