The International Simutrans Forum

Simutrans Extended => Simutrans-Extended development => Topic started by: Philip on September 14, 2013, 05:09:44 PM

Title: [passenger-generation] corrupt building lists
Post by: Philip on September 14, 2013, 05:09:44 PM
I'm not 100% sure this fixes the hard-to-reproduce segfaults I've been seeing, but I suspect it does. The problem is in weighted_vector_tpl::remove_all, which fails to remove the second of two consecutive copies of the same element.


diff --git a/tpl/weighted_vector_tpl.h b/tpl/weighted_vector_tpl.h
index 50c355d..c682a57 100644
--- a/tpl/weighted_vector_tpl.h
+++ b/tpl/weighted_vector_tpl.h
@@ -325,7 +325,10 @@ template<class T> class weighted_vector_tpl
bool any_to_remove = false;
for (uint32 i = 0; i < count; i++)
{
- if (nodes != NULL && nodes[i].data == elem) any_to_remove = remove_at(i);
+ if (nodes != NULL && nodes[i].data == elem) {
+ any_to_remove = remove_at(i);
+ i--;
+ }
}
return any_to_remove;
}




EDIT: but why did we see duplicate entries at all? I think here's why:


diff --git a/simcity.cc b/simcity.cc
index 195699a..08033ce 100644
--- a/simcity.cc
+++ b/simcity.cc
@@ -5538,7 +5538,7 @@ void stadt_t::add_building_to_list(gebaeude_t* building, bool ordered)
                // single-threaded). This must be added elsewhere if this is a network game.

                // All types of city building generate/receive mail.
-               welt->add_building_to_world_list(building, karte_t::visitor_target);
+               welt->add_building_to_world_list(building, karte_t::mail_origin_or_target);

                if(building->get_haustyp() == gebaeude_t::wohnung)
                {
Title: Re: [passenger-generation] corrupt building lists
Post by: jamespetts on September 14, 2013, 08:18:48 PM
Thank you very much for that - that is most helpful indeed. I had been wondering what residual errors were causing these problems, and had hoped that I had fixed them, but had evidently missed one or two points. Thank you!