Author: mordante
Date: Sat Oct 15 20:06:24 2011
New Revision: 51494

URL: http://svn.gna.org/viewcvs/wesnoth?rev=51494&view=rev
Log:
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.)

Modified:
    trunk/src/unit.cpp
    trunk/src/unit.hpp

Modified: trunk/src/unit.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=51494&r1=51493&r2=51494&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Sat Oct 15 20:06:24 2011
@@ -2799,6 +2799,14 @@
 
 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_;
 }
 

Modified: trunk/src/unit.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.hpp?rev=51494&r1=51493&r2=51494&view=diff
==============================================================================
--- trunk/src/unit.hpp (original)
+++ trunk/src/unit.hpp Sat Oct 15 20:06:24 2011
@@ -467,8 +467,16 @@
        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();


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to