@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.