diff --git a/Source/Engine/Content/Asset.cpp b/Source/Engine/Content/Asset.cpp index da6b7329a..66ff7a93e 100644 --- a/Source/Engine/Content/Asset.cpp +++ b/Source/Engine/Content/Asset.cpp @@ -429,6 +429,9 @@ void Asset::Reload() ScopeLock lock(Locker); + // Cancel any still-running loading task (e.g. if WaitForLoaded timed out) + Platform::AtomicStore(&_loadingTask, 0); + if (IsLoaded()) { // Unload current data @@ -611,6 +614,13 @@ bool Asset::onLoad(LoadAssetTask* task) Locker.Lock(); + // Re-check after acquiring lock (loading task may have been cleared by Reload, or replaced by a new task) + if (Platform::AtomicRead(&_loadingTask) == 0) + { + Locker.Unlock(); + return true; + } + // Load asset LoadResult result; #if USE_EDITOR