Skip to content

Commit 650ba00

Browse files
committed
fix(physics): crash when deleting parts due to misusing simulationTicket iterator
1 parent df79548 commit 650ba00

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

core/src/objects/part.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void Part::OnWorkspaceAdded(std::optional<std::shared_ptr<Workspace>> oldWorkspa
5454
}
5555

5656
void Part::OnWorkspaceRemoved(std::shared_ptr<Workspace> oldWorkspace) {
57-
if (simulationTicket->get() != nullptr)
57+
if (simulationTicket.has_value())
5858
oldWorkspace->RemoveBody(shared<Part>());
5959
}
6060

core/src/objects/part.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class DEF_INST_(explorer_icon="part") Part : public PVInstance {
109109
DEF_SIGNAL SignalSource TouchEnded;
110110

111111
rp::RigidBody* rigidBody = nullptr;
112-
SimulationTicket simulationTicket;
112+
std::optional<SimulationTicket> simulationTicket;
113113
bool rigidBodyDirty = true;
114114

115115
inline SurfaceType GetSurfaceFromFace(NormalId face) { return surfaceFromFace(face); }

core/src/objects/service/workspace.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ void Workspace::PhysicsStep(float deltaTime) {
165165
if (item.action == QueueItem::QUEUEITEM_ADD) {
166166
simulatedBodies.push_back(item.part);
167167
item.part->simulationTicket = --simulatedBodies.end();
168-
} else if (item.part->simulationTicket->get() != nullptr) {
169-
simulatedBodies.erase(item.part->simulationTicket);
170-
item.part->simulationTicket = {};
168+
} else if (item.part->simulationTicket.has_value()) {
169+
simulatedBodies.erase(item.part->simulationTicket.value());
170+
item.part->simulationTicket = std::nullopt;
171171
}
172172
}
173173
queueLock.unlock();

0 commit comments

Comments
 (0)