Revision: 2526 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2526&view=rev Author: ulteq Date: 2012-05-07 20:21:40 +0000 (Mon, 07 May 2012) Log Message: ----------- -Bugfix: #939 Hooks crashing the game when "T"-screen is open
Modified Paths: -------------- trunk/source/main/physics/Beam.cpp Modified: trunk/source/main/physics/Beam.cpp =================================================================== --- trunk/source/main/physics/Beam.cpp 2012-05-07 07:30:45 UTC (rev 2525) +++ trunk/source/main/physics/Beam.cpp 2012-05-07 20:21:40 UTC (rev 2526) @@ -1307,7 +1307,7 @@ BES_GFX_STOP(BES_GFX_calc_masses2); } -// this recalcs the masses, useful when the gravity was changed... +// this recalculates the masses (useful when the gravity was changed...) void Beam::recalc_masses() { this->calc_masses2(totalmass, true); @@ -1315,17 +1315,37 @@ float Beam::getTotalMass(bool withLocked) { - float mass = totalmass; //already computed in calc_masses2 - if (withLocked) + if (!withLocked) return totalmass; // already computed in calc_masses2 + + bool found = true; + float mass = 0.0f; + std::map< Beam*, bool> lookup_table; + std::pair<std::map< Beam*, bool>::iterator, bool> ret; + + lookup_table.insert(std::pair< Beam*, bool>(this, false)); + + while (found) { - for(std::vector<hook_t>::iterator it=hooks.begin(); it!=hooks.end(); it++) + found = false; + + for (std::map< Beam*, bool>::iterator it_beam=lookup_table.begin(); it_beam != lookup_table.end(); ++it_beam) { - if(it->lockTruck && it->lockTruck->getTruckName() != getTruckName()) + if (!it_beam->second) { - mass += it->lockTruck->getTotalMass(); + for (std::vector<hook_t>::iterator it_hook=it_beam->first->hooks.begin(); it_hook != it_beam->first->hooks.end(); ++it_hook) + { + if (it_hook->lockTruck) + { + ret = lookup_table.insert(std::pair< Beam*, bool>(it_hook->lockTruck, false)); + found = found || ret.second; + } + } + mass += it_beam->first->totalmass; + it_beam->second = true; } } } + return mass; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Rigsofrods-devel mailing list Rigsofrods-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel