From f6d30fcf9b3f8d2a3580a07b2735cfa87fee55b1 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Tue, 5 May 2026 09:03:02 -0700 Subject: [PATCH] fix(editor): ghost preview survives object rebuilds, clearObjects resets ghost state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Ghost model state (ID, path, active flag) properly reset when clearObjects() wipes the M2 renderer — prevents stale ghost references causing crashes on subsequent hover - Ghost model ID uses 59999 to avoid collision with placed object IDs - Ghost loadModel failure now handled gracefully (returns early) --- tools/editor/editor_viewport.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/editor/editor_viewport.cpp b/tools/editor/editor_viewport.cpp index bbb35f1d..5da01854 100644 --- a/tools/editor/editor_viewport.cpp +++ b/tools/editor/editor_viewport.cpp @@ -97,6 +97,12 @@ void EditorViewport::placeWMO(const std::string& path, const glm::vec3& pos, } void EditorViewport::clearObjects() { + // Clear ghost state since the M2 renderer is about to be wiped + ghostActive_ = false; + ghostInstanceId_ = 0; + ghostModelId_ = 0; + ghostModelPath_.clear(); + if (m2Renderer_) { vkCtx_->waitAllUploads(); m2Renderer_->clear(); @@ -406,8 +412,11 @@ void EditorViewport::setGhostPreview(const std::string& path, const glm::vec3& p if (!model.isValid()) return; if (model.boundRadius < 1.0f) model.boundRadius = 50.0f; - ghostModelId_ = 60000; // Use a high ID to avoid collision with placed objects - m2Renderer_->loadModel(model, ghostModelId_); + ghostModelId_ = 59999; // High ID to avoid collision with placed objects + if (!m2Renderer_->loadModel(model, ghostModelId_)) { + ghostModelId_ = 0; + return; + } vkCtx_->waitAllUploads(); vkCtx_->pollUploadBatches(); ghostModelPath_ = path;