Author: thonsew
Date: Tue Aug 30 06:38:36 2011
New Revision: 50951

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50951&view=rev
Log:
Added a work around for unit id collisions in the unit_map due to changes 
outside the unit map.
Added a request for a bug report concering these collisions.
Fixed a memory leak.

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

Modified: trunk/src/unit_map.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_map.cpp?rev=50951&r1=50950&r2=50951&view=diff
==============================================================================
--- trunk/src/unit_map.cpp (original)
+++ trunk/src/unit_map.cpp Tue Aug 30 06:38:36 2011
@@ -80,7 +80,9 @@
        self_check();
        unit *p = new unit(u);
        p->set_location(l);
-       return insert(p);
+       std::pair<unit_map::unit_iterator, bool> res( insert(p) );
+       if(res.second == false) { delete p; }
+       return res;
 }
 
 std::pair<unit_map::unit_iterator, bool> unit_map::move(const map_location 
&src, const map_location &dst) {
@@ -175,7 +177,20 @@
 
                        p->clone(false);
                        uinsert = 
umap_.insert(std::make_pair(p->underlying_id(), lit ));
-                       if (!uinsert.second) { bool never_happen(false); 
assert(never_happen); }
+                       int guard(0);
+                       while (!uinsert.second && (++guard < 1e6) ) {
+                               if(guard % 10 == 9){
+                                       ERR_NG << "\n\nPlease Report this error 
to https://gna.org/bugs/index.php?18591 " 
+                                               "\nIn addition to the standard 
details of operating system and wesnoth version "
+                                               "and how it happened, please 
answer the following questions "
+                                               "\n 1. Were you playing 
mutli-player?"
+                                               "\n 2. Did you 
start/restart/reload the game/scenario?"
+                                               "\nThank you for your help in 
fixing this bug.\n";
+                               }
+                               p->clone(false);
+                               uinsert = 
umap_.insert(std::make_pair(p->underlying_id(), lit )); }
+                       if (!uinsert.second) { 
+                               throw "One million collisions in unit_map"; }
                }
        }
 

Modified: trunk/src/unit_map.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_map.hpp?rev=50951&r1=50950&r2=50951&view=diff
==============================================================================
--- trunk/src/unit_map.hpp (original)
+++ trunk/src/unit_map.hpp Tue Aug 30 06:38:36 2011
@@ -408,10 +408,6 @@
         */
        unit *extract(const map_location &loc);
 
-       ///Finds and deletes the umap_ item associated with @a lit when the 
underlying_id()
-       ///has been changed externally after insertion and before extraction
-       void error_recovery_externally_changed_uid(t_ilist::iterator const & 
lit) const;
-
        ///Checks invariants.  For debugging purposes only.  Doesn't do 
anything in non-debug mode.
        bool self_check() const
 #ifndef DEBUG
@@ -453,6 +449,9 @@
                if (!is_found( i )) { return const_unit_iterator(the_end_, 
this); }
                return const_unit_iterator(i , this); }
 
+       ///Finds and deletes the umap_ item associated with @a lit when the 
underlying_id()
+       ///has been changed externally after insertion and before extraction
+       void error_recovery_externally_changed_uid(t_ilist::iterator const & 
lit) const;
 
        /**
         * underlying_id -> ilist::iterator. This requires that underlying_id be


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

Reply via email to