aboutsummaryrefslogtreecommitdiff
path: root/src/moveuse.cc
diff options
context:
space:
mode:
authorfusion32 <marcopuzziello@gmail.com>2026-02-26 22:31:03 -0300
committerfusion32 <marcopuzziello@gmail.com>2026-02-26 22:31:03 -0300
commit1738b5f5c82ec942ab0b1ca176559e071767138b (patch)
treeb1278ee1fb6a61441b97caaaf966e4f3e69d52bf /src/moveuse.cc
parent419e6bf9902851e23b4dfe04918521c9d19be524 (diff)
downloadgame-1738b5f5c82ec942ab0b1ca176559e071767138b.tar.gz
game-1738b5f5c82ec942ab0b1ca176559e071767138b.zip
fix issue with collision events (#54)
Diffstat (limited to 'src/moveuse.cc')
-rw-r--r--src/moveuse.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/moveuse.cc b/src/moveuse.cc
index 0bf932c..0bfa319 100644
--- a/src/moveuse.cc
+++ b/src/moveuse.cc
@@ -2401,12 +2401,19 @@ void CollisionEvent(Object Obj, Object Dest){
Object Help = GetFirstContainerObject(Dest);
while(Help != NONE){
Object Next = Help.getNextObject();
+
+ // IMPORTANT(fusion): Same as below.
+ if(Next == Obj){
+ Next = Next.getNextObject();
+ }
+
if(Help != Obj){
HandleEvent(MOVEUSE_EVENT_COLLISION, NONE, Obj, Help);
if(!Obj.exists()){
throw DESTROYED;
}
}
+
Help = Next;
}
}
@@ -2415,6 +2422,20 @@ void CollisionEvent(Object Obj, Object Dest){
Object Help = GetFirstContainerObject(Dest);
while(Help != NONE){
Object Next = Help.getNextObject();
+
+ // IMPORTANT(fusion): This is very subtle but the collision event can
+ // move or destroy either object, causing it to be removed from the
+ // container list while we're still iterating it.
+ // It won't be a problem most of the time, but if Next happens to be
+ // Obj, and it gets moved, we could end up iterating the remainder of
+ // whatever list Obj now belongs to, causing side effects like double
+ // collision effects, etc...
+ // Note that this cannot happen to Help simply because it is already
+ // behind the Next pointer, so checking only for Obj here is enough.
+ if(Next == Obj){
+ Next = Next.getNextObject();
+ }
+
if(Help != Obj){
ObjectType HelpType = Help.getObjectType();
if(HelpType.getFlag(TELEPORTABSOLUTE) || HelpType.getFlag(TELEPORTRELATIVE)){
@@ -2446,6 +2467,7 @@ void CollisionEvent(Object Obj, Object Dest){
throw DESTROYED;
}
}
+
Help = Next;
}
}