Pathoschild / SMAPI

The modding API for Stardew Valley.
https://smapi.io/
GNU Lesser General Public License v3.0
1.89k stars 265 forks source link

Prevent parallel asset loads/edits during save processing #403

Closed Pathoschild closed 6 years ago

Pathoschild commented 6 years ago

Prevent IAssetEditor and IAssetLoader implementations from being called while the game is reading/writing a save (without preventing mods from editing or loading any assets).

Background

The game uses asynchronous logic to read/write the save file, so SMAPI blocks mod events until the asynchronous task is done to prevent errors with non-thread-safe data. However, IAssetEditor/IAssetLoader implementations still run during the async save/load. That can cause various cryptic errors (e.g. 'collection modified' or 'can't load PNG during draw loop' exceptions).

The attached mod and save files reproduces the issue. It has an IAssetEditor to intercept tree images to patch in custom trees, which occasionally fails due to async race conditions.

Pathoschild commented 6 years ago

Done with c8ae8c2b0021401783ac38a80db7e676674f623a in SMAPI 2.6-beta.6.