diff --git a/Source/Engine/Content/Asset.cpp b/Source/Engine/Content/Asset.cpp index 8d520a62d..380cef278 100644 --- a/Source/Engine/Content/Asset.cpp +++ b/Source/Engine/Content/Asset.cpp @@ -324,15 +324,14 @@ void Asset::Reload() Content::AssetReloading(this); OnReloading(this); - // Fire unload event - // TODO: maybe just call release storage ref or sth? we cannot call onUnload because managed asset objects gets invalidated - //onUnload_MainThread(); - ScopeLock lock(Locker); - // Unload current data - unload(true); - _isLoaded = false; + if (IsLoaded()) + { + // Unload current data + unload(true); + _isLoaded = false; + } // Start reloading process startLoading(); diff --git a/Source/Engine/ShadersCompilation/ShadersCompilation.cpp b/Source/Engine/ShadersCompilation/ShadersCompilation.cpp index 21d564668..9e56367a6 100644 --- a/Source/Engine/ShadersCompilation/ShadersCompilation.cpp +++ b/Source/Engine/ShadersCompilation/ShadersCompilation.cpp @@ -19,6 +19,8 @@ #include "Engine/Profiler/ProfilerCPU.h" #include "Engine/Serialization/MemoryReadStream.h" #include "Engine/Content/Asset.h" +#include "Engine/Content/Content.h" +#include "Engine/Content/Assets/Shader.h" #if USE_EDITOR #define COMPILE_WITH_ASSETS_IMPORTER 1 // Hack to use shaders importing in this module #include "Engine/ContentImporters/AssetsImportingManager.h" @@ -56,7 +58,6 @@ using namespace ShadersCompilationImpl; class ShadersCompilationService : public EngineService { public: - ShadersCompilationService() : EngineService(TEXT("Shaders Compilation Service"), -100) { @@ -250,6 +251,7 @@ namespace if (action == FileSystemAction::Delete) return; + // Get list of assets using this shader file Array toReload; { ScopeLock lock(ShaderIncludesMapLocker); @@ -260,6 +262,13 @@ namespace toReload = file->Value; } + // Add any shaders that failed to load (eg. due to error in included header) + for (Asset* asset : Content::GetAssets()) + { + if (asset->LastLoadFailed() && asset->Is() && !toReload.Contains(asset)) + toReload.Add(asset); + } + LOG(Info, "Shader include \'{0}\' has been modified.", path); // Wait a little so app that was editing the file (e.g. Visual Studio, Notepad++) has enough time to flush whole file change