-
-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wzapi: change
removeObject
API function to defer object removal
Introduce `scriptQueuedObjectRemovals()` vector to hold deferred object removal requests from `wzapi::removeObject` API. `wzapi::removeObject` API call adds the game objects to this list. They will eventually be released during calls to `processScriptQueuedObjectRemovals()` during the following stages of the main game loop: 1. `recvMessage()` - there are a few functions which distribute resources of the defeated players among others and may trigger script events. 2. `updateScripts()` - processes queued timer functions. 3. `droidUpdate()`, `missionDroidUpdate()`, `structureUpdate()` - main routines for updating the state of in-game objects. These would potentially trigger the majority of script events. Each pair represents `<GameObject, NeedToApplyEffectsOnDestruction>` tuple. The sole reason for this breaking API change is to guard against cases like this one: 1. `gameStateUpdate()` processes droid state updates inside a `mutating_list_iterate`. 2. A droid update triggers some user script, which calls `wzapi::removeObject` several times in a row. 3. This may potentially destroy `itNext` iterator saved inside the `mutating_list_iterate` from of the upper stack frames, which would lead to invalid memory access. So, instead of removing multiple objects inside of `mutating_list_iterate`, which is unsafe, we just queue removal requests and execute actual destruction routines once we are out of the `mutating_list_iterate` function. Signed-off-by: Pavel Solodovnikov <[email protected]>
- Loading branch information
Showing
3 changed files
with
116 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters