diff --git a/core/src/objects/jointsservice.cpp b/core/src/objects/jointsservice.cpp index fa3ac26..d13d489 100644 --- a/core/src/objects/jointsservice.cpp +++ b/core/src/objects/jointsservice.cpp @@ -1,5 +1,6 @@ #include "jointsservice.h" #include "workspace.h" +#include const InstanceType JointsService::TYPE = { .super = &Instance::TYPE, @@ -21,6 +22,11 @@ JointsService::~JointsService() = default; void JointsService::InitService() { if (initialized) return; initialized = true; + + // Clear children before any new joints are added + for (std::shared_ptr inst : dataModel().value()->GetService()->GetChildren()) { + inst->Destroy(); + } } std::optional> JointsService::jointWorkspace() { diff --git a/editor/mainwindow.cpp b/editor/mainwindow.cpp index 7877de2..03f0594 100644 --- a/editor/mainwindow.cpp +++ b/editor/mainwindow.cpp @@ -177,7 +177,7 @@ MainWindow::MainWindow(QWidget *parent) snap->c1 = part0->cframe; // gWorkspace()->AddChild(snap); - gDataModel->GetService()->AddChild(snap); + gWorkspace()->AddChild(snap); snap->UpdateProperty("Part0"); snap->UpdateProperty("Part1"); }