In orx 1.6 release, I've been struggling with a nasty bug that occasionally crashes my game. I've chased the bug down to the following sequence of events.
I have a ScoreDisplay (scroll)object and it has a IncreaseScore method, which creates ScorePiece (scroll)objects that fly towards the ScoreDisplay. The IncreaseScore creates the ScorePiece objects as an owned child of the ScoreDisplay.
The flying towards the display is handled in ScorePiece::Update, where I query the position of the ScoreDisplay by "GetPos"ing its "Owner".
The crash happens when I delete the ScoreDisplay while there are "ScorePiece"s flying towards it. I'm printing out a lot of stuff for debug purposes and I can see that while the ScoreDisplay is being deleted, the "ScorePiece"s are still among its Owned children and their Refcount is 1. All the other children of the ScoreDisplay get deleted right after the ScoreDisplay but not the "ScorePiece"s. I can also see that in the last ScorePiece::Update that causes the crash, its GetOwner returns null.
I could dodge this bug by simply checking in ScorePiece::Update whether the owner is null, but the trouble is there are many places in the project where I assume no ScrollObject::Update would be called after the owner of an object is deleted. Is that a wrong assumption? If not, why could this be happening and how can I debug it?
Note that I've considered the possibility of memory corruption, but I've run the game under Valgrind and it reports no errors. I can also consistently reproduce the bug under different build configurations (release/debug) and I really doubt a memory corruption could manifest itself so consistently.