News:

Congratulations!
 You've won the News Item Lottery! Your prize? Reading this news item! :)

[passenger-generation] corrupt building lists

Started by Philip, September 14, 2013, 05:09:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Philip

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)
                {

jamespetts

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!
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.