Author: ai0867
Date: Thu Jan 14 20:52:42 2010
New Revision: 40698

URL: http://svn.gna.org/viewcvs/wesnoth?rev=40698&view=rev
Log:
Fix the teleport-pathfind crash bug by adding a copy-constructor and 
copy-assignment operator for teleport_map.

Modified:
    branches/fendrin_pathfind/src/pathfind.cpp
    branches/fendrin_pathfind/src/pathfind.hpp

Modified: branches/fendrin_pathfind/src/pathfind.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_pathfind/src/pathfind.cpp?rev=40698&r1=40697&r2=40698&view=diff
==============================================================================
--- branches/fendrin_pathfind/src/pathfind.cpp (original)
+++ branches/fendrin_pathfind/src/pathfind.cpp Thu Jan 14 20:52:42 2010
@@ -65,6 +65,59 @@
        } else if (destinations_it != destinations_.end()) {
                ERR_PF << "More destinations than sources\n";
        }
+}
+
+teleport_map::teleport_map(const teleport_map &other) : teleport_map_(), 
sources_(other.sources_), destinations_(other.destinations_), empty_() {
+       std::vector<std::set<map_location> >::iterator destinations_it = 
destinations_.begin();
+       std::vector<std::set<map_location> >::iterator sources_it = 
sources_.begin();
+       for (; sources_it != sources_.end() && destinations_it != 
destinations_.end();) {
+               for (std::set<map_location>::iterator it2 = 
sources_it->begin(); it2 != sources_it->end(); ++it2) {
+                       //std::stringstream ss;
+                       //ss << "Adding teleporter: (" << it2->x << ',' << 
it2->y << ") -> ";
+                       //foreach(const map_location &dest, (*destinations_it))
+                       //      ss << '(' << dest.x << ',' << dest.y << "),";
+                       //ss << "\n";
+                       //ERR_PF << ss.str();
+                       teleport_map_.insert(std::make_pair(*it2, 
&(*destinations_it)));
+               }
+               ++sources_it;
+               ++destinations_it;
+       }
+       if (sources_it != sources_.end()) {
+               ERR_PF << "More sources than destinations\n";
+       } else if (destinations_it != destinations_.end()) {
+               ERR_PF << "More destinations than sources\n";
+       }
+}
+
+teleport_map& teleport_map::operator=(const teleport_map &other) {
+       if (this == &other)
+               return *this;
+       destinations_ = other.destinations_;
+       sources_ = other.sources_;
+       teleport_map_ = std::map<map_location, const std::set<map_location>* 
const>();
+
+       std::vector<std::set<map_location> >::iterator destinations_it = 
destinations_.begin();
+       std::vector<std::set<map_location> >::iterator sources_it = 
sources_.begin();
+       for (; sources_it != sources_.end() && destinations_it != 
destinations_.end();) {
+               for (std::set<map_location>::iterator it2 = 
sources_it->begin(); it2 != sources_it->end(); ++it2) {
+                       //std::stringstream ss;
+                       //ss << "Adding teleporter: (" << it2->x << ',' << 
it2->y << ") -> ";
+                       //foreach(const map_location &dest, (*destinations_it))
+                       //      ss << '(' << dest.x << ',' << dest.y << "),";
+                       //ss << "\n";
+                       //ERR_PF << ss.str();
+                       teleport_map_.insert(std::make_pair(*it2, 
&(*destinations_it)));
+               }
+               ++sources_it;
+               ++destinations_it;
+       }
+       if (sources_it != sources_.end()) {
+               ERR_PF << "More sources than destinations\n";
+       } else if (destinations_it != destinations_.end()) {
+               ERR_PF << "More destinations than sources\n";
+       }
+       return *this;
 }
 
 //TODO move to the right place

Modified: branches/fendrin_pathfind/src/pathfind.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_pathfind/src/pathfind.hpp?rev=40698&r1=40697&r2=40698&view=diff
==============================================================================
--- branches/fendrin_pathfind/src/pathfind.hpp (original)
+++ branches/fendrin_pathfind/src/pathfind.hpp Thu Jan 14 20:52:42 2010
@@ -40,6 +40,8 @@
 public:
        teleport_map(std::vector<teleport_group> teleport_groups);
        teleport_map() : teleport_map_(), sources_(), destinations_(), empty_() 
{};
+       teleport_map(const teleport_map &other);
+       teleport_map& operator=(const teleport_map &other);
 
        const std::set<map_location>& get_adjacents(map_location loc) const;
        bool empty() const { return sources_.empty(); }
@@ -48,7 +50,7 @@
        const std::vector<std::set<map_location> >& get_destinations() const 
{return destinations_; };
 
 private:
-       std::map<map_location, std::set<map_location>* > teleport_map_;
+       std::map<map_location, const std::set<map_location>* const > 
teleport_map_;
        std::vector<std::set<map_location> > sources_;
        std::vector<std::set<map_location> > destinations_;
        std::set<map_location> empty_;


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

Reply via email to