JonathanTroyer / Progress-Renderer

A mod for Rimworld. Automatically create scheduled renderings of the full map or only a chosen part of it.
GNU Lesser General Public License v3.0
2 stars 4 forks source link

Race condition when rendering multiple maps #30

Closed XenoTheStrange closed 3 months ago

XenoTheStrange commented 3 months ago

The problem of it switching to a random map is due to several instances of the DoRender function running at the same time, so while one changes the map to render it the other is saving that map as the one to return to instead of the proper one: image

This image should be a good indicator of what's going on. I'm not sure what a good fix would be without introducing artificial lag by making the functions wait for each-other.

Since the mod needs to switch to another map in order to render it, multiple renders should not happen simultaneously.

Originally posted by @XenoTheStrange in https://github.com/JonathanTroyer/Progress-Renderer/issues/29#issuecomment-2033145365

XenoTheStrange commented 3 months ago

Example of a bugged set of captures caused by this error: rimworld-wise-Map-0-PlayerHome-000004 rimworld-wise-Map-1-000004 rimworld-wise-Map-2-000004 rimworld-wise-Map-3-000004 rimworld-wise-Map-4-000004

XenoTheStrange commented 3 months ago

The captures that should have been made: rimworld-wise-Map-0-PlayerHome-5500-1-06-09 (filesize too large) rimworld-wise-Map-1-5500-1-06-09 rimworld-wise-Map-2-5500-1-06-09 rimworld-wise-Map-3-5500-1-06-09 rimworld-wise-Map-4-5500-1-06-09

XenoTheStrange commented 3 months ago

I was originally trying to figure out / fix how the game would force-switch your map after rendering but it turns out the problem is bigger than that.

To reproduce: Just have multiple maps and set them to render at an interval. You won't get the proper output most of the time, it's somewhat random because it depends in what order the renders run and how long each takes.

XenoTheStrange commented 3 months ago

Maybe set some global "Rendering" variable so each map component will wait for the other one to finish rendering before it goes? Idk.

There is something similar that prevents this sort of scenario if one map tries to render while it's already rendering.

JonathanTroyer commented 3 months ago

Fixed by https://github.com/JonathanTroyer/Progress-Renderer/commit/3855bfa8505607f5b9fb6cb2249db3d24897336b