News:

Simutrans Wiki Manual
The official on-line manual for Simutrans. Read and contribute.

0 div in fabrik_t::recalc_demands_at_target_cities

Started by poppo, Yesterday at 03:07:47 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

poppo

when a factory has many target cities, we use weight of distance.
in this case, when sum_of_weight=0, we cannot calculate pax_amount and mail_amount because divided by 0.
so, we should add guards on line 536 and 538 in simfab.cc:

- const uint32 pax_amount = (uint32)(( (sint64)(scaled_pax_demand << DEMAND_BITS) * (sint64)weights[c] + (sint64)(sum_of_weights >> 1) ) / (sint64)sum_of_weights);
+ const uint32 pax_amount = sum_of_weights<1? 0u: (uint32)(( (sint64)(scaled_pax_demand << DEMAND_BITS) * (sint64)weights[c] + (sint64)(sum_of_weights >> 1) ) / (sint64)sum_of_weights);
target_cities[c]->access_target_factories_for_pax().update_factory(this, pax_amount);
- const uint32 mail_amount = (uint32)(( (sint64)(scaled_mail_demand << DEMAND_BITS) * (sint64)weights[c] + (sint64)(sum_of_weights >> 1) ) / (sint64)sum_of_weights);
+ const uint32 mail_amount = sum_of_weights<1? 0u: (uint32)(( (sint64)(scaled_mail_demand << DEMAND_BITS) * (sint64)weights[c] + (sint64)(sum_of_weights >> 1) ) / (sint64)sum_of_weights);
target_cities[c]->access_target_factories_for_mail().update_factory(this, mail_amount);
}