bvschaik / julius

An open source re-implementation of Caesar III
GNU Affero General Public License v3.0
2.85k stars 317 forks source link

Rare house corruption issue #696

Closed crudelios closed 11 months ago

crudelios commented 1 year ago

https://github.com/bvschaik/julius/blob/bae63eb689737a720445f614ead61f41f86cbb9e/src/figuretype/migrant.c#L282

Buckle up because the above line causes rare corruptions.

So, as you may notice above, the code for a homeless entering a house does not check for the house state, only if the building type is a house.

On some rare occasions (it requires a very specific set of circumstances that I'll describe below) that will cause corruptions.

The requirements are:

If all the conditions are met, the homeless will enter a house with the state of BUILDING_STATE_DELETED_BY_GAME.

However, upon entering, the map building tiles will be updated to point to the zombie building id.

Also, when building_update_state is called, the building will finally be deleted and the tile will point to a non existent building.

This will obviously corrupt the city, but only briefly: if the 2x2 evolves the tile reference will be updated again so the issue should fix itself.

Anyway, it's a pretty interesting and rare bug.

This is causing crashes in Augustus however, due to the different way memory is handled there.

bvschaik commented 1 year ago

Interesting one. What do you suggest to do to fix the issue without breaking compatibility? Or should we leave it as-is for Julius since it fixes itself in the end?

crudelios commented 1 year ago

A simple check for the building state when the homeless arrives should prevent the issue in the future. If it's not a house or it's not BUILDING_STATE_IN_USE when the homeless arrives, simply kill him.

crudelios commented 1 year ago

Here's the relevant changed I used to fix the issue in Augustus:

https://github.com/Keriew/augustus/commit/b51cfaf864579ed0e48ec8de01fcf5c821de1b23#diff-17376d420a8b1b25d89314eda333aa555795549d6346f9097210f902626f7bc7

crudelios commented 11 months ago

@bvschaik Do you want me to fix this issue?

crudelios commented 11 months ago

This was unexpected. The change is failing the tests!

I'll have to revert them.

crudelios commented 11 months ago

Given that the fix changes the save results, I'm thinking we simply don't fix it.

bvschaik commented 11 months ago

I was afraid it would. I agree with not fixing this.