Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2]

Author Topic: WINE crashes starting at 2013 Elections  (Read 2767 times)

Purple Gorilla

  • Bay Watcher
    • View Profile
Re: WINE crashes starting at 2013 Elections
« Reply #15 on: May 25, 2015, 09:56:56 am »

OK, I was playing around with the savefile from the coredump and got some information :
* Occationally it works on its own. The Propositions are Pollution, Labour Rights, Immigration and a fourth (women,abortion). Its always four, so the engine must pick four (25% chance) and randomly give one of the almost-zero issues one point.
* If I cause havoc at the Jugment Halls, (liberizing free speach, abortion, woman rights, homosexuality and death penalty) the game works with a higher probability and might pick more than four laws.
Theese findings imply, that the bug happens if there are not enough laws to chance. This also matches with playing experience, as this seems to happen in three situations :
* Low profile start (here done)
* Dealing with the CCS or sieges without making "politics"
* If you are short before winning

In my old thread I anounced the hypothesis that the canlaw array may be empty and an acces to it doesn't check if it is empty. In 4.7.0 it is in line 571 in politics.cpp. In 4.7.4 this wasn't changed (line 390 in politics.cpp ).

Apperently, this acces doesn't cause problems but sets the law number to a bogus value (edx=0012faa8). If the game tries to print the proposition things go to hell :
politics.cpp line 600 :
Code: [Select]
         if(propdir[p]==1)set_color(COLOR_GREEN,COLOR_BLACK,1);
This command compares an entry in a local array to the immediate 1.
Most likely the symbols :
Code: [Select]
esi=propdir
edx=p
The following comparisons and jumps are probably the switch/case block.

This raises the Question, why line  575 (    lawtaken[prop[p]]=1;) doesn't cause a segfault, as it writes to the location.
Possible solutions :
* The compiler optimized this line to something, that doesn't cause a seg fault (the are multiple ways to implement indexing in assembly)
* The adress is coincidently write only
* The compiler's code interceps bad writes, but not bad reads

Purple Gorilla

  • Bay Watcher
    • View Profile
Re: WINE crashes starting at 2013 Elections
« Reply #16 on: May 25, 2015, 12:09:18 pm »

I finally managed to compile the game, and found the Bug.
Getting the Game compiled took hours, but finding the bug - a typo - took minutes  :).

And sorry, it was indeed fixed in 4.7.4.

I'm still not sure what happens if canlaw is empty, but this is probably rare.


Line 688:

.            case LAW_PRISONS:
.               if(propdir[c]==1)
.               {
.                  if(law[LAW_PRISONS]==1) addstr("Establish Prison Rehabilitation");
.                  else addstr("Improve Prison Conditions");
.               }
.               else addstr("Increase Prison Security");
.               break;
Should be:

.            case LAW_PRISONS:
.               if(propdir[p]==1)
.               {
.                  if(law[LAW_PRISONS]==1) addstr("Establish Prison Rehabilitation");
.                  else addstr("Improve Prison Conditions");
.               }
.               else addstr("Increase Prison Security");
.               break;

All other checks check for p, that contains the law number, but this one checks for c. If the president was not elected, that year, c is uninitialised and containes garbage. If the president was elected, c is 2 and the comparison acceses police brutality. I remember, that sometimes in President-Election-Years a law pops up, that look that Increase Prison Security. This happens, if the View on Prisons is Liberal, but the View on Police Brutality is Conservative, and the Prisons Law is chanced by a proposition in a year then the President is elected.

If you think about Obama and Guantanamo Bay, it makes even some sence then the Liberals make the Prison system more conservative   :)

FinetalPies

  • Bay Watcher
  • Even on the battlefield.
    • View Profile
Re: WINE crashes starting at 2013 Elections
« Reply #17 on: May 25, 2015, 03:50:37 pm »

Nicely done. Thanks for going through all that effort. I'm pretty useless when it comes to this stuff so I just sit and watch in awe, hahaha
Logged

SlatersQuest

  • Bay Watcher
    • View Profile
Re: WINE crashes starting at 2013 Elections
« Reply #18 on: May 25, 2015, 06:48:06 pm »

Curious - I just looked through the Mac version source code, and unless I'm looking in the wrong place (politics.cpp?), the bug isn't there.

Well done! :)
Logged

Purple Gorilla

  • Bay Watcher
    • View Profile
Re: WINE crashes starting at 2013 Elections
« Reply #19 on: May 27, 2015, 07:14:01 am »

No Problem. At least that Bug pushed me to get the Game compiled and start modding  :).

By the Way, is there an "easy" way to get it compiled with Bloodshed Dev-C ? If you import the MSC projekt it only includes the files in the SRC directory and if you use the makefile, it doesn't find the files in the subdirectories. I got around by adding all CPP files (execpt those in src\sandbox) manually to a project and adding all subdirectories of src to the include directories. Then however it works fine.
Pages: 1 [2]