- prevent appearance of dangling pointers in corpse queue

A dangling pointer in corpse queue may appear if actor is added to the queue when GC is in propagation state.
Enqueued corpse actor remains white, and if it’s destroyed and garbage collected before dequeue, a dangling pointer will be accessed during its removal from the queue.
In console, do `summon CorpseSpawner` and `gc now` with the following script loaded. Without a write barrier, it will crash in two seconds.

```
class TestCorpse : Actor
{
	States
	{
	Spawn:
		POSS U 1 A_Die;
	Death:
		POSS U 1 A_QueueCorpse;
		Stop;
	}
}

class CorpseSpawner : Actor
{
	override void Tick()
	{
		A_SpawnItem("TestCorpse");
	}
}
```

https://forum.zdoom.org/viewtopic.php?t=69842
This commit is contained in:
alexey.lysiuk 2021-06-30 10:19:08 +03:00
parent 9b3782ea0f
commit a9ad3d1fc3

View file

@ -105,6 +105,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_QueueCorpse)
corpsequeue.Delete(0);
}
corpsequeue.Push(self);
GC::WriteBarrier(self);
}
return 0;
}