Okay, I'm lucky this time I happened to be running under the debugger
when I got a segmentation fault. (It should *not* be necessary to run
under the debugger. Programs that crash should leave core dump
files.)
This time, the guilty code is in NewNicowar::control_attacks. (I have
no idea if this is related to the segmentation violation I reported
earlier.) For reference, I've appended the code of this function
below.
This code is doing several things that I don't understand.
The part most directly at fault is that it is assuming the command b =
echo.get_building_register().get_building(i) stores a valid building
in b. This time, it does not, and dereferencing the building with
b->locked[true] causes a crash. So it should definitely check that b
is valid before using it.
get_building(i) should *always* be valid, this is an echo semantic, as long as I is up to date. Nicowar uses iterating to find buildings. I will investigate this further.
But anyway, how could this call possibly work? The number i is an
index of an attack flag. (Right?) How could this possibly be
connected to swimming pools? And why is code for controlling attack
flags concerned with swimming pools at all?
Maybe this is code that was copied from elsewhere and insufficiently
adapted afterward?
I'm confused.
--
Joe
======================================================================
void NewNicowar::control_attacks(Echo& echo)
{
choose_enemy_target(echo);
if(target!=-1)
{
int number_attacks=0;
if(war)
{
number_attacks=2;
}
if(attack_flags.size() < number_attacks)
{
attack_building(echo);
}
}
BuildingSearch bs_pool(echo);
bs_pool.add_condition(new SpecificBuildingType(IntBuildingType::SWIMSPEED_BUILDING));
int num_pool=bs_pool.count_buildings();
for(int i=0; i<attack_flags.size(); ++i)
{
Building* b = echo.get_building_register().get_building(i);
if((num_pool && b->locked[true]) || (num_pool==0 && b->locked[false]))
{
ManagementOrder* mo_destroy=new DestroyBuilding(i);
echo.add_management_order(mo_destroy);
}
}
}
_______________________________________________
glob2-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/glob2-devel