mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-06 21:43:45 +00:00
Harden unit_movement_resetter class.
Add a warning regarding its usage and test whether the unit exists before assigning to it. (Still a bit experimental, but initial tests show no regressions.)
This commit is contained in:
parent
9a44eaaa76
commit
af7ef732bd
@ -2799,6 +2799,14 @@ unit_movement_resetter::unit_movement_resetter(unit &u, bool operate) :
|
||||
|
||||
unit_movement_resetter::~unit_movement_resetter()
|
||||
{
|
||||
assert(resources::units);
|
||||
|
||||
/*
|
||||
* This assert should be safe, but not 100% sure so if it fails need
|
||||
* some extra validation code in this function.
|
||||
*/
|
||||
assert(resources::units->has_unit(&u_));
|
||||
|
||||
u_.movement_ = moves_;
|
||||
}
|
||||
|
||||
|
10
src/unit.hpp
10
src/unit.hpp
@ -467,8 +467,16 @@ private:
|
||||
void clear_visibility_cache() const { invisibility_cache_.clear(); }
|
||||
};
|
||||
|
||||
/** Object which temporarily resets a unit's movement */
|
||||
/**
|
||||
* Object which temporarily resets a unit's movement.
|
||||
*
|
||||
* @warning
|
||||
* The unit whose movement is reset may not be deleted while a
|
||||
* @ref unit_movement_resetter object 'holds'. So best use it only in a small
|
||||
* scope.
|
||||
*/
|
||||
struct unit_movement_resetter
|
||||
: private boost::noncopyable
|
||||
{
|
||||
unit_movement_resetter(unit& u, bool operate=true);
|
||||
~unit_movement_resetter();
|
||||
|
Loading…
x
Reference in New Issue
Block a user