From 9af72b3ba1e0904611b3e81a39492f6d06d9d4f1 Mon Sep 17 00:00:00 2001 From: hhhxiao <1417599491@qq.com> Date: Mon, 5 Sep 2022 15:18:06 +0800 Subject: [PATCH] Fix: crash when remove a component adjested to a repeator or comparator --- src/opts/RedstoneOpt.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/opts/RedstoneOpt.cpp b/src/opts/RedstoneOpt.cpp index c024ce7..5a14dfb 100644 --- a/src/opts/RedstoneOpt.cpp +++ b/src/opts/RedstoneOpt.cpp @@ -126,7 +126,10 @@ void optPendingRemoves(CircuitSceneGraph *graph) { auto updateComponent = allComp.second.get(); // 不是消费者才尝试移除 - // updateComponent->removeSource(pos, targetComp); + // 这里可以对中继器和比较器做一些特判,不是这些原件可以吧remove source挪动到后面 + // 中继器的不能挪到后面是因为中继器的这个函数还会移除侧边原件,这些原件不是信号源 + // 暂时先这么写,有空再优化 + updateComponent->removeSource(pos, targetComp); auto &ss = dAccess, 8>(updateComponent); auto ssit = ss.begin(); size_t res = 0; @@ -134,14 +137,14 @@ void optPendingRemoves(CircuitSceneGraph *graph) { if (ssit->mPos == pos || ssit->mComponent == targetComp) { graph->scheduleRelationshipUpdate(allComp.first, updateComponent); ss.erase(ssit); + ++res; } else { ++ssit; - ++res; } } - if (res != 0) { - updateComponent->removeSource(pos, targetComp); - } + // if (res != 0) { + // updateComponent->removeSource(pos, targetComp); + // } } }