修复碎片模型卸载的在飞 GPU 引用(vkDestroyBuffer in-use):门面批量卸载先 WaitDeviceIdle 再销毁(与 ReloadMaterialAsset 同一先例)

This commit is contained in:
2026-10-08 23:23:15 +08:00
parent affa1a7a56
commit 2cf8d6e076
2 changed files with 24 additions and 18 deletions
+10 -4
View File
@@ -182,11 +182,17 @@ namespace Engine
ModelRef LoadModel(const std::string& path, ParsedModel&& parsed);
Model* GetModel(ModelRef h) const { return m_Models.Get(h); }
void UnloadModel(ModelRef h) { m_Models.Unload(h); }
// 按路径卸载模型(未加载为 no-op;手上只有路径的场景,
// 如脚本程序化碎片模型回收)
void UnloadModelByPath(const std::string& path)
// 批量按路径卸载模型(未加载为 no-op)。先 GPU 全停飞再销毁
//(在飞命令缓冲可能仍引用顶点缓冲/默认纹理 sampler——
// 与 ReloadMaterialAsset 的 WaitDeviceIdle 同一先例);一次
// 停飞摊薄整批,调用方攒批降频(脚本碎片回收每帧一批)
void UnloadModelsByPaths(const std::vector<std::string>& paths)
{
m_Models.UnloadByPath(path);
if (paths.empty()) return;
m_Uploader.WaitDeviceIdle();
for (const std::string& p : paths) {
m_Models.UnloadByPath(p);
}
}
// 按路径查已加载的模型(未加载返回 null,不触发加载)——
// 面板 hover 信息卡用