Author Topic: Matron puts Torturer to rest crash -- SOLVED!!  (Read 3910 times)

0 Members and 1 Guest are viewing this topic.

Offline Aika

  • Full Member
  • ***
  • Posts: 138
Matron puts Torturer to rest crash -- SOLVED!!
« on: June 10, 2012, 02:39:29 PM »
I did some digging through the code and discovered what causes this. When the game updates the dungeon, it first checks a flag to see if torturing was done. This flag is updated in WorkTorturer.cpp, so if there's a girl doing torturing, the flag is set. If the torturedone flag is set, it then runs a function to return the reference to the girl that did the torturing. It does this by checking all the girls to see which of them CURRENTLY has the torturer job, but it does this AFTER the matron code is run.

If the torturedone flag is set, the game assumes that there's a torturer. If the WhoHasTorturerJob function doesn't find the torturer (which happens if the matron put her off work), it returns a 0 to the dungeon update function, instead of the girl structure reference it needs. Then the dungeon update function tries to find the girl's name variable in the reference that has been passed to it. It was passed a 0 instead of a reference to a girl structure. CRASH.

To fix this, we need the WhoHasTorturerJob function to find the girl that was put to rest by the matron. This is as easy as changing the line in cBrothel.cpp (should be around line 5000) that reads

Code: [Select]
if(curGirl->m_DayJob == JOB_TORTURER)
to

Code: [Select]
if((curGirl->m_DayJob == JOB_TORTURER) || (curGirl->m_PrevDayJob == JOB_TORTURER))
And one irritating, frustrating bug is squashed.

I know I got longwinded and technical here. Sorry.
« Last Edit: June 10, 2012, 03:47:40 PM by Aika »

Offline Xela

  • Global Moderator
  • *****
  • Posts: 6870
  • "It's like hunting cows"
Re: Matron puts Torturer to rest crash -- SOLVED!!
« Reply #1 on: June 10, 2012, 02:58:24 PM »
Nice catch, this was bugging WM for a long time, hard to believe it could be fixed in one line :)
Like what we're doing?

Offline Kenki

  • Newbie
  • *
  • Posts: 35
Re: Matron puts Torturer to rest crash -- SOLVED!!
« Reply #2 on: June 10, 2012, 03:03:23 PM »
@Aika,

I am not familiar with the code(PrevDayJob), but how would that work if the you just set one of your girls to Torture the past turn, and there were not Torturers before? Is that a variable that is Saved/Loaded, what would happen if you just loaded the game from scratch and ran it?


Wouldn't it make more sense to have the Dungeon Update not only set the Torture flag but also set the reference for which girl is currently working as a Torturer? Another way may be to have the the WorkTorture completely update before having the matron code run, if possible. Just trying to make sure that your hotfix covers all conceivable scenarios.

Offline Aika

  • Full Member
  • ***
  • Posts: 138
Re: Matron puts Torturer to rest crash -- SOLVED!!
« Reply #3 on: June 10, 2012, 03:11:17 PM »
@Aika,

I am not familiar with the code(PrevDayJob), but how would that work if the you just set one of your girls to Torture the past turn, and there were not Torturers before? Is that a variable that is Saved/Loaded, what would happen if you just loaded the game from scratch and ran it?

The PrevDayJob variable is only modified by the Matron code. It's used to track which job the girl had before the matron put her to rest so when the girl is rested the matron can put her back to work on the job she had before. It is set when the matron puts a girl to rest, and cleared when the girl is put back to work. It is saved and loaded. This is not a new variable I put in to make this work, this is an existing variable already implemented with the matron code. The possible problems you're mentioning would be true with any job, not just the torturer job, if the Matron code were not working properly. The hotfix fixes a crash caused by the matron code, and the key to resolving the crash also resides in the matron code, IE the PrevDayJob variable. This does not cause any additional bugs.

Wouldn't it make more sense to have the Dungeon Update not only set the Torture flag but also set the reference for which girl is currently working as a Torturer? Another way may be to have the the WorkTorture completely update before having the matron code run, if possible. Just trying to make sure that your hotfix covers all conceivable scenarios.
 

Having the dungeon update set the torture flag if there is a torturer would cause another kind of bug; the Torturer has worked her shift before the matron put her off duty, but the dungeon update is run after the matron put her to rest, so the people in the dungeon wouldn't be tortured. This would work, but it wouldn't work right.

All the WorkTorture function does is update the torturedone flag, update the girl's stats, and pay the girl. It does completely run before the matron code runs. But the matron code runs before the dungeon updates, and the dungeon update is what's causing the crash if the WorkTorturer function has run and the Matron put the torturer off shift. There's also no way to set the dungeon to update between the job code and the matron code; it would update the dungeon once for every brothel you have.

This may be a complex bug, but it doesn't have to have a complex solution. This fixes the bug, works, and doesn't cause any additional problems. Simple solutions are best.
« Last Edit: June 10, 2012, 03:22:40 PM by Aika »

Offline crazy

  • Hero Member
  • *****
  • Posts: 732
Re: Matron puts Torturer to rest crash -- SOLVED!!
« Reply #4 on: June 10, 2012, 03:40:52 PM »
Nice find.  Thanks for sharing the fix.

Offline Aika

  • Full Member
  • ***
  • Posts: 138
Re: Matron puts Torturer to rest crash -- SOLVED!!
« Reply #5 on: June 10, 2012, 03:49:07 PM »
Slight change to the fix code, edited in the original post. The fix was right, but the syntax was wrong.