Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve safety of KeyObserverMap::observeKey()
Although the use of lambdas instead of KeyObserver references is cleaner and *appears* safer, it actually introduces potential undefined behaviour of its own: the lambda might capture variables which are destroyed before the observer is disconnected in the EntityNode/KeyObserverMap destructor. This is actually the case in live code, for example in StaticGeometryNode where observeKey() is called with lambdas that refer to m_rotationKey, which is a subclass member which will be destroyed before EntityNode itself. KeyObserverMap's internal implementation is now changed to use sigc::signals (one per observed key), and the KeyObserverFunc is upgraded from an std::function into a sigc::slot. This allows the use of auto-disconnection if the slot is set up using sigc::mem_fun instead of a lambda. The auto-disconnection behaviour is now confirmed with a new unit test.
- Loading branch information
Matthew Mott
committed
Dec 9, 2021
1 parent
966d6b1
commit 0242f77
Showing
3 changed files
with
73 additions
and
18 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