The International Simutrans Forum

 

Author Topic: [passenger-generation] corrupt building lists  (Read 801 times)

0 Members and 1 Guest are viewing this topic.

Offline Philip

  • *
  • Posts: 90
  • Languages: EN
[passenger-generation] corrupt building lists
« 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.

Code: [Select]
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:

Code: [Select]
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)
                {
« Last Edit: September 14, 2013, 05:34:53 PM by Philip »

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18755
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: [passenger-generation] corrupt building lists
« Reply #1 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!