DarkRadiant: master 0242f774

Author Committer Branch Timestamp Parent
orbweaver orbweaver master 09.12.2021 13:12 master 966d6b1a
Changeset 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.
mod - include/ientity.h Diff File
mod - radiantcore/entity/KeyObserverMap.h Diff File
mod - test/Entity.cpp Diff File