fix(editor): unload ghost preview model when path changes

setGhostPreview reused modelId 59999 for every preview, but loadModel
returns true without doing anything when the ID is already cached. So
selecting a new NPC kept the old ghost model in GPU memory and createInstance
used the stale model. Added M2Renderer::unloadModel public API and call it
from clearGhostPreview.
This commit is contained in:
Kelsi 2026-05-06 00:51:22 -07:00
parent ca630c4e87
commit 1c3307a0b6
3 changed files with 14 additions and 1 deletions

View file

@ -543,6 +543,15 @@ void M2Renderer::cleanupUnusedModels() {
}
}
void M2Renderer::unloadModel(uint32_t modelId) {
auto it = models.find(modelId);
if (it == models.end()) return;
if (vkCtx_) vkDeviceWaitIdle(vkCtx_->getDevice());
destroyModelGPU(it->second);
models.erase(it);
modelUnusedSince_.erase(modelId);
}
VkTexture* M2Renderer::loadTexture(const std::string& path, uint32_t texFlags) {
constexpr uint64_t kFailedTextureRetryLookups = 512;
auto normalizeKey = [](std::string key) {