Fix error when loading surface from not yet loaded asset

This commit is contained in:
Wojtek Figat
2022-05-06 18:30:49 +02:00
parent 4cedd0f30c
commit 78d6fe6b50
9 changed files with 25 additions and 6 deletions

View File

@@ -350,7 +350,7 @@ namespace ContentLoadingManagerImpl
extern ConcurrentTaskQueue<ContentLoadTask> Tasks;
};
bool Asset::WaitForLoaded(double timeoutInMilliseconds)
bool Asset::WaitForLoaded(double timeoutInMilliseconds) const
{
// This function is used many time when some parts of the engine need to wait for asset loading end (it may fail but has to end).
// But it cannot be just a simple active-wait loop.
@@ -376,7 +376,7 @@ bool Asset::WaitForLoaded(double timeoutInMilliseconds)
// If running on a main thread we can flush asset `Loaded` event
if (IsInMainThread())
{
Content::tryCallOnLoaded(this);
Content::tryCallOnLoaded((Asset*)this);
}
return false;
@@ -467,7 +467,7 @@ bool Asset::WaitForLoaded(double timeoutInMilliseconds)
// If running on a main thread we can flush asset `Loaded` event
if (IsInMainThread() && IsLoaded())
{
Content::tryCallOnLoaded(this);
Content::tryCallOnLoaded((Asset*)this);
}
return _isLoaded == 0;

View File

@@ -154,7 +154,7 @@ public:
/// </summary>
/// <param name="timeoutInMilliseconds">Custom timeout value in milliseconds.</param>
/// <returns>True if cannot load that asset (failed or has been cancelled), otherwise false.</returns>
API_FUNCTION() bool WaitForLoaded(double timeoutInMilliseconds = 30000.0);
API_FUNCTION() bool WaitForLoaded(double timeoutInMilliseconds = 30000.0) const;
/// <summary>
/// Initializes asset data as virtual asset.

View File

@@ -129,6 +129,8 @@ bool AnimationGraph::InitAsAnimation(SkinnedModel* baseModel, Animation* anim, b
BytesContainer AnimationGraph::LoadSurface()
{
if (!IsVirtual() && WaitForLoaded())
return BytesContainer();
ScopeLock lock(Locker);
if (IsVirtual())

View File

@@ -54,6 +54,8 @@ AssetChunksFlag AnimationGraphFunction::getChunksToPreload() const
BytesContainer AnimationGraphFunction::LoadSurface() const
{
BytesContainer result;
if (WaitForLoaded())
return result;
ScopeLock lock(Locker);
result.Link(GraphData);
return result;

View File

@@ -431,7 +431,7 @@ void Material::InitCompilationOptions(ShaderCompilationOptions& options)
options.Macros.Add({ "USE_GBUFFER_CUSTOM_DATA", Numbers[useCustomData ? 1 : 0] });
options.Macros.Add({ "USE_REFLECTIONS", Numbers[info.FeaturesFlags & MaterialFeaturesFlags::DisableReflections ? 0 : 1] });
if (!(info.FeaturesFlags & MaterialFeaturesFlags::DisableReflections) && info.FeaturesFlags & MaterialFeaturesFlags::ScreenSpaceReflections)
options.Macros.Add({ "MATERIAL_REFLECTIONS", Numbers[1]});
options.Macros.Add({ "MATERIAL_REFLECTIONS", Numbers[1] });
options.Macros.Add({ "USE_FOG", Numbers[info.FeaturesFlags & MaterialFeaturesFlags::DisableFog ? 0 : 1] });
if (useForward)
options.Macros.Add({ "USE_PIXEL_NORMAL_OFFSET_REFRACTION", Numbers[info.FeaturesFlags & MaterialFeaturesFlags::PixelNormalOffsetRefraction ? 1 : 0] });
@@ -476,6 +476,8 @@ void Material::InitCompilationOptions(ShaderCompilationOptions& options)
BytesContainer Material::LoadSurface(bool createDefaultIfMissing)
{
BytesContainer result;
if (WaitForLoaded())
return result;
ScopeLock lock(Locker);
// Check if has that chunk

View File

@@ -75,6 +75,8 @@ AssetChunksFlag MaterialFunction::getChunksToPreload() const
BytesContainer MaterialFunction::LoadSurface()
{
BytesContainer result;
if (WaitForLoaded())
return result;
ScopeLock lock(Locker);
if (HasChunk(0))
{
@@ -89,6 +91,8 @@ BytesContainer MaterialFunction::LoadSurface()
bool MaterialFunction::LoadSurface(MaterialGraph& graph)
{
if (WaitForLoaded())
return true;
ScopeLock lock(Locker);
if (HasChunk(0))
{

View File

@@ -2116,6 +2116,8 @@ const VisualScript::Field* VisualScript::FindField(const StringAnsiView& name) c
BytesContainer VisualScript::LoadSurface()
{
if (WaitForLoaded())
return BytesContainer();
ScopeLock lock(Locker);
if (!LoadChunks(GET_CHUNK_FLAG(0)))
{
@@ -2124,7 +2126,6 @@ BytesContainer VisualScript::LoadSurface()
result.Copy(data->Data);
return result;
}
LOG(Warning, "\'{0}\' surface data is missing.", ToString());
return BytesContainer();
}

View File

@@ -335,6 +335,8 @@ void ParticleEmitter::InitCompilationOptions(ShaderCompilationOptions& options)
BytesContainer ParticleEmitter::LoadSurface(bool createDefaultIfMissing)
{
BytesContainer result;
if (WaitForLoaded())
return result;
ScopeLock lock(Locker);
// Check if has that chunk

View File

@@ -84,6 +84,8 @@ AssetChunksFlag ParticleEmitterFunction::getChunksToPreload() const
bool ParticleEmitterFunction::LoadSurface(ParticleEmitterGraphCPU& graph)
{
if (WaitForLoaded())
return true;
ScopeLock lock(Locker);
if (HasChunk(0))
{
@@ -102,6 +104,8 @@ bool ParticleEmitterFunction::LoadSurface(ParticleEmitterGraphCPU& graph)
BytesContainer ParticleEmitterFunction::LoadSurface()
{
BytesContainer result;
if (WaitForLoaded())
return result;
ScopeLock lock(Locker);
if (HasChunk(0))
{
@@ -118,6 +122,8 @@ BytesContainer ParticleEmitterFunction::LoadSurface()
bool ParticleEmitterFunction::LoadSurface(ParticleEmitterGraphGPU& graph)
{
if (WaitForLoaded())
return true;
ScopeLock lock(Locker);
if (HasChunk(0))
{