fix(editor): begin upload batch before M2 model loading in rebuild

rebuildObjects() calls clearObjects() which clears the M2 renderer,
but didn't start a new upload batch before loading models. The M2
renderer needs an active upload batch context to upload vertex/index
buffers to the GPU. Without it, loadModel may silently fail.

Now calls vkCtx_->beginUploadBatch() after clear and before the
model loading loop. Also adds diagnostic logging when loadModel
fails for NPCs (shows vertex/index/batch counts).
This commit is contained in:
Kelsi 2026-05-05 22:40:58 -07:00
parent 98223995fc
commit 072d0f78c2

View file

@ -119,6 +119,7 @@ void EditorViewport::rebuildObjects(const std::vector<PlacedObject>& objects,
clearObjects();
if (objects.empty() && npcs.empty()) return;
vkCtx_->beginUploadBatch();
uint32_t nextModelId = 1;
std::unordered_map<std::string, uint32_t> m2ModelIds, wmoModelIds;
@ -359,7 +360,12 @@ void EditorViewport::rebuildObjects(const std::vector<PlacedObject>& objects,
}
if (!ok) { LOG_WARNING("NPC M2 bad vertices: ", npc.modelPath); continue; }
modelId = nextModelId++;
if (!m2Renderer_->loadModel(model, modelId)) continue;
if (!m2Renderer_->loadModel(model, modelId)) {
LOG_WARNING("NPC M2 loadModel failed: ", npc.modelPath,
" (", model.vertices.size(), "v ", model.indices.size(), "i ",
model.batches.size(), "b)");
continue;
}
vkCtx_->waitAllUploads();
vkCtx_->pollUploadBatches();
m2ModelIds[npc.modelPath] = modelId;