Ensure MapCache disposes cleanly.

This prevents the map loading thread writing to disposed objects which can have unintended side effects.
This commit is contained in:
RoosterDragon
2015-04-01 20:33:51 +01:00
parent 14e9cfd433
commit 47e2c48068

View File

@@ -250,7 +250,20 @@ namespace OpenRA
public void Dispose() public void Dispose()
{ {
sheetBuilder.Dispose(); if (previewLoaderThread == null)
{
sheetBuilder.Dispose();
return;
}
// We need to let the loader thread exit before we can dispose our sheet builder.
// Ideally we should dispose our resources before returning, but we don't to block waiting on the loader thread to exit.
// Instead, we'll queue disposal to be run once it has exited.
ThreadPool.QueueUserWorkItem(_ =>
{
previewLoaderThread.Join();
Game.RunAfterTick(sheetBuilder.Dispose);
});
} }
} }
} }