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

Segmentation fault (core dumped) #228

Closed tmr83 closed 2 years ago

tmr83 commented 2 years ago

I took this screenshot and then exited 7kaa by clicking on the window's X. That is when it segfaulted.

Screenshot from 2021-12-25 16-15-18

Program terminated with signal SIGSEGV, Segmentation fault.

0 Town::set_nation (this=0x55c5bb161c90, newNationRecno=0) at OTOWN.cpp:835

835 if( firmPtr->firm_ai ) // tell linked firms that this town has changed nation [Current thread is 1 (Thread 0x7f250c71f780 (LWP 3126))] (gdb) bt full

0 Town::set_nation (this=0x55c5bb161c90, newNationRecno=0) at OTOWN.cpp:835

    oldNationRecno = 1
    i = 0
    nationRaceId = <optimized out>
    firmPtr = 0x0

1 0x000055c5b76ed3b7 in NationBase::deinit (this=this@entry=0x55c5bac9f660)

at ONATIONB.cpp:222
    townPtr = <optimized out>
    i = 45

2 0x000055c5b7668b39 in Nation::deinit (this=0x55c5bac9f660)

at OAI_MAIN.cpp:90

No locals.

3 0x000055c5b76ecb37 in NationArray::del_nation (

this=0x55c5b7805f60 <nation_array>, recNo=1) at ONATIONA.cpp:275
    nationPtr = 0x55c5bac9f660

4 0x000055c5b76ecc3f in NationArray::deinit (

this=0x55c5b7805f60 <nation_array>) at ONATIONA.cpp:97
    i = <optimized out>

5 0x000055c5b76a8d46 in Game::deinit (this=0x55c5b7804b40 ,

loadGameCall=0) at OGAME.cpp:258
    oldCursor = 13

6 0x000055c5b76ba3b5 in Game::run_main_menu_option (

this=this@entry=0x55c5b7804b40 <game>, optionId=optionId@entry=1)

--Type for more, q to quit, c to continue without paging-- at OGAMMAIN.cpp:304 No locals.

7 0x000055c5b76ba638 in Game::main_menu (this=0x55c5b7804b40 )

at OGAMMAIN.cpp:256
    newPointingOption = <optimized out>
    Game::MAIN_OPTION_COUNT = Game::MAIN_OPTION_COUNT
    main_option_array = {{x1 = 264, y1 = 205, x2 = 540, y2 = 257}, {
        x1 = 264, y1 = 262, x2 = 540, y2 = 307}, {x1 = 264, y1 = 315, 
        x2 = 540, y2 = 370}, {x1 = 264, y1 = 378, x2 = 540, y2 = 416}, {
        x1 = 264, y1 = 418, x2 = 540, y2 = 489}, {x1 = 298, y1 = 491, 
        x2 = 512, y2 = 531}}
    main_option_flag = "\001\001\001\001\001\001"
    refreshFlag = 0
    i = 0
    optionInfo = 0x55c5b7801b00 <Game::main_menu()::main_option_array>
    menuBitmap = 0x0
    brightBitmap = 0x0
    darkBitmap = 0x0
    pointingOption = <optimized out>

8 0x000055c5b765a840 in main (argc=1, argv=0x7ffd38e2b118) at AM.cpp:368

No locals.

tmr83 commented 2 years ago

Here is another backtrace from a different segfault. This one happened after having 18+ towns linked to the same fort when I noticed that some towns are governed by the leader in the fort but do not have the visual link when the fort is selected. I abandoned a majority of the towns. I then sold my fort, and this is when 7kaa segfaulted.

Program terminated with signal SIGSEGV, Segmentation fault.

0 Town::distribute_demand (this=0x55f6a0ae9ae0) at OTOWN.cpp:3141

3141 if( firmPtr->firm_id != FIRM_MARKET ) [Current thread is 1 (Thread 0x7f3483aa1780 (LWP 2823))] (gdb) bt full

0 Town::distribute_demand (this=0x55f6a0ae9ae0) at OTOWN.cpp:3141

linkedFirmId = 0 i = j = firmPtr = 0x0 marketGoodsInfoArray = {{market_ptr = {0x0 <repeats 20 times>}, total_supply = 0, total_own_supply = 0, market_count = 0}, { market_ptr = {0x0 <repeats 20 times>}, total_supply = 0, total_own_supply = 0, market_count = 0}, {market_ptr = { 0x0 <repeats 20 times>}, total_supply = 0, total_own_supply = 0, market_count = 0}} marketGoodsInfo = thisSupply = 3.0836974e-41 marketGoods = townDemand = -6.55621415e-21 ownShareDemand = firmMarket =

1 0x000055f69d3dfd2c in TownArray::distribute_demand (this=)

at OTOWNA.cpp:759 i = 59 j = firmMarket =

2 0x000055f69d3da143 in Town::toggle_firm_link (

--Type for more, q to quit, c to continue without paging-- this=this@entry=0x55f6a0ae3d40, linkId=linkId@entry=1, toggleFlag=, remoteAction=remoteAction@entry=2 '\002', setBoth=setBoth@entry=0) at OTOWN.cpp:3571 linkedFirm = linkedNationRecno = sameNation = firmPtr = i =

3 0x000055f69d3e8e02 in Town::think_independent_set_link (

this=0x55f6a0ae3d40) at OTOWNIND.cpp:119 i = 0 linkStatus = firmPtr =

4 0x000055f69d3e9400 in Town::think_independent_town (this=0x55f6a0ae3d40)

at OTOWNIND.cpp:61 No locals.

5 0x000055f69d3dfed8 in TownArray::process (this=0x55f69d4a9100 )

at OTOWNA.cpp:196 i = 14 townPtr = 0x55f6a0ae3d40

6 0x000055f69d3d06d9 in Sys::process (this=this@entry=0x55f69d4ad8c0 )

at OSYS2.cpp:140 No locals. --Type for more, q to quit, c to continue without paging--

7 0x000055f69d3cee3f in Sys::main_loop (

this=this@entry=0x55f69d4ad8c0 , isLoadedGame=isLoadedGame@entry=1) at OSYS.cpp:841 rc = 1 markTime = 12918 unreadyPlayerFlag = 0 lastDispFrameTime = 12915 firstUnreadyTime = 5323

8 0x000055f69d3cf281 in Sys::run (this=0x55f69d4ad8c0 ,

isLoadedGame=isLoadedGame@entry=1) at OSYS.cpp:588 No locals.

9 0x000055f69d314b3f in Battle::run_loaded (this=)

at OBATTLE.cpp:653 kingRace = songId =

10 0x000055f69d35cc03 in Game::single_player_menu (this=0x55f69d4a7b40 )

at OGAMMAIN.cpp:628 i = 2 newPointingOption = optionInfo = 0x55f69d4a4ad0 <Game::single_player_menu()::single_player_option_array+16> Game::SINGLE_PLAYER_OPTION_COUNT = Game::SINGLE_PLAYER_OPTION_COUNT single_player_option_array = {{x1 = 263, y1 = 204, x2 = 540, --Type for more, q to quit, c to continue without paging-- y2 = 256}, {x1 = 263, y1 = 261, x2 = 540, y2 = 306}, {x1 = 263, y1 = 314, x2 = 540, y2 = 369}, {x1 = 263, y1 = 376, x2 = 540, y2 = 417}, {x1 = 298, y1 = 432, x2 = 512, y2 = 474}} single_player_option_flag = "\001\001\001\001\001" refreshFlag = 1 i = menuBitmap = brightBitmap = darkBitmap = pointingOption =

11 0x000055f69d35d3b5 in Game::run_main_menu_option (

this=this@entry=0x55f69d4a7b40 , optionId=optionId@entry=1) at OGAMMAIN.cpp:304 No locals.

12 0x000055f69d35d638 in Game::main_menu (this=0x55f69d4a7b40 )

at OGAMMAIN.cpp:256 newPointingOption = Game::MAIN_OPTION_COUNT = Game::MAIN_OPTION_COUNT main_option_array = {{x1 = 264, y1 = 205, x2 = 540, y2 = 257}, { x1 = 264, y1 = 262, x2 = 540, y2 = 307}, {x1 = 264, y1 = 315, x2 = 540, y2 = 370}, {x1 = 264, y1 = 378, x2 = 540, y2 = 416}, { x1 = 264, y1 = 418, x2 = 540, y2 = 489}, {x1 = 298, y1 = 491, x2 = 512, y2 = 531}} --Type for more, q to quit, c to continue without paging-- main_option_flag = "\001\001\001\001\001\001" refreshFlag = 0 i = 0 optionInfo = 0x55f69d4a4b00 <Game::main_menu()::main_option_array> menuBitmap = 0x0 brightBitmap = 0x0 darkBitmap = 0x0 pointingOption =

13 0x000055f69d2fd840 in main (argc=1, argv=0x7ffe34549a18) at AM.cpp:368

No locals.

the3dfxdude commented 2 years ago

Congrats. You managed to break the game. Please send the save file

the3dfxdude commented 2 years ago

In OTOWN.cpp line 3308: if( firmPtr->linked_town_count < MAX_LINKED_TOWN_TOWN )

Change to if( firmPtr->linked_town_count < MAX_LINKED_FIRM_TOWN )

You will need to relayout the towns in a new game each time to test with 18+ towns. After the objects are corrupted, there is no way to fix it.

The code needs a bit of rework, because this one line might not be enough to prevent an issue with a more diverse layout.

tmr83 commented 2 years ago

Seems fine so far with that change.

the3dfxdude commented 2 years ago

Ok, I think I got a better fix. I additionally tried the following to make sure there is no crash. Note, that there are still maximums, that the game devs knew that were for practical gameplay. These layouts are not reasonable in any way. When the maximum is hit, you will notice that not every structure will have a link associated. Towns do have the Town Network, but may not show up as directly linked, and that is fine. 7K23 7K24