the3dfxdude / 7kaa

Seven Kingdoms: Ancient Adversaries - Go to the main source repository at https://sourceforge.net/projects/skfans/ for source code and builds
https://7kfans.com
Other
253 stars 71 forks source link

segfault when attacking a ship entering a harbor #123

Closed jeanguyomarch closed 5 years ago

jeanguyomarch commented 5 years ago

I had ballistas firing on an enemy ship that were sailing back to its harbor : 7kaa-bug

It is followed by a segmentation fault. This is always reproducible. Below is the stackstrace as displayed by gdb:

Thread 1 "7kaa" received signal SIGSEGV, Segmentation fault.
Unit::attack_unit (this=0x55555662f5e0, targetRecno=<optimized out>, xOffset=0, yOffset=0, resetBlockedEdge=1) at OUNITAT2.cpp:202
202                             if(!possible_place_for_range_attack(targetXLoc, targetYLoc, unitPtr->sprite_info->loc_width, unitPtr->sprite_info->loc_height, maxRange))
(gdb) bt
#0  Unit::attack_unit (this=0x55555662f5e0, targetRecno=<optimized out>, xOffset=0, yOffset=0, resetBlockedEdge=1) at OUNITAT2.cpp:202
#1  0x000055555566652e in Unit::idle_detect_choose_target (this=0x55555662f5e0, defenseMode=<optimized out>) at OUNITI.cpp:1129
#2  0x00005555556668dd in Unit::idle_detect_attack (this=this@entry=0x55555662f5e0, startLoc=startLoc@entry=0, dimensionInput=dimensionInput@entry=0, defenseMode=defenseMode@entry=0 '\000') at OUNITI.cpp:761
#3  0x0000555555666cd5 in Unit::process_idle (this=0x55555662f5e0) at OUNITI.cpp:264
#4  0x0000555555624807 in SpriteArray::process (this=0x5555556f61e0 <unit_array>) at OSPRITEA.cpp:279
#5  0x000055555564f699 in UnitArray::process (this=<optimized out>) at OUNITA.cpp:607
#6  0x000055555562f2bd in Sys::process (this=this@entry=0x5555556fa8a0 <sys>) at OSYS2.cpp:134
#7  0x000055555562daba in Sys::main_loop (this=this@entry=0x5555556fa8a0 <sys>, isLoadedGame=isLoadedGame@entry=1) at OSYS.cpp:828
#8  0x000055555562df05 in Sys::run (this=0x5555556fa8a0 <sys>, isLoadedGame=isLoadedGame@entry=1) at OSYS.cpp:575
#9  0x000055555557d64d in Battle::run_loaded (this=<optimized out>) at OBATTLE.cpp:652
#10 0x00005555555c1bb6 in Game::single_player_menu (this=0x5555556f4b60 <game>) at OGAMMAIN.cpp:625
#11 0x00005555555c2355 in Game::run_main_menu_option (this=this@entry=0x5555556f4b60 <game>, optionId=optionId@entry=1) at OGAMMAIN.cpp:306
#12 0x00005555555c25d3 in Game::main_menu (this=0x5555556f4b60 <game>) at OGAMMAIN.cpp:256
#13 0x000055555556851d in main (argc=1, argv=0x7fffffffdcd8) at AM.cpp:360

The faulty code is below:

   │200                             maxRange = max_attack_range();                                                                                                                                                                            │
   │201                             Unit *unitPtr = unit_array[locPtr->unit_recno(targetMobileType)];                                                                                                                                         │
  >│202                             if(!possible_place_for_range_attack(targetXLoc, targetYLoc, unitPtr->sprite_info->loc_width, unitPtr->sprite_info->loc_height, maxRange))                                                                 │
   │203                             {

unitPtr is NULL, and therefore the evalulation of the parameters of function possible_place_for_range_attack yields to an invalid memory access.

the3dfxdude commented 5 years ago

What kind of ships does purple have?

Edit: Here is how to identify visually- 1 sail - trader (note, looking down the bow, there is a second very small one, hardly seen from the side) 2 sails - transport 3 sails - caravel 4 sails - galleon

Also these rank from smallest to largest in size

jeanguyomarch commented 5 years ago

These are transport ships. I don't know if they contain troops.

the3dfxdude commented 5 years ago

This should be fixed by 767f8c1915d9ed964c64b556663df293d89bddbe

jeanguyomarch commented 5 years ago

Thanks.