Fix error when loading surface from not yet loaded asset
This commit is contained in:
@@ -350,7 +350,7 @@ namespace ContentLoadingManagerImpl
|
|||||||
extern ConcurrentTaskQueue<ContentLoadTask> Tasks;
|
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).
|
// 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.
|
// 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 running on a main thread we can flush asset `Loaded` event
|
||||||
if (IsInMainThread())
|
if (IsInMainThread())
|
||||||
{
|
{
|
||||||
Content::tryCallOnLoaded(this);
|
Content::tryCallOnLoaded((Asset*)this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -467,7 +467,7 @@ bool Asset::WaitForLoaded(double timeoutInMilliseconds)
|
|||||||
// If running on a main thread we can flush asset `Loaded` event
|
// If running on a main thread we can flush asset `Loaded` event
|
||||||
if (IsInMainThread() && IsLoaded())
|
if (IsInMainThread() && IsLoaded())
|
||||||
{
|
{
|
||||||
Content::tryCallOnLoaded(this);
|
Content::tryCallOnLoaded((Asset*)this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _isLoaded == 0;
|
return _isLoaded == 0;
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="timeoutInMilliseconds">Custom timeout value in milliseconds.</param>
|
/// <param name="timeoutInMilliseconds">Custom timeout value in milliseconds.</param>
|
||||||
/// <returns>True if cannot load that asset (failed or has been cancelled), otherwise false.</returns>
|
/// <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>
|
/// <summary>
|
||||||
/// Initializes asset data as virtual asset.
|
/// Initializes asset data as virtual asset.
|
||||||
|
|||||||
@@ -129,6 +129,8 @@ bool AnimationGraph::InitAsAnimation(SkinnedModel* baseModel, Animation* anim, b
|
|||||||
|
|
||||||
BytesContainer AnimationGraph::LoadSurface()
|
BytesContainer AnimationGraph::LoadSurface()
|
||||||
{
|
{
|
||||||
|
if (!IsVirtual() && WaitForLoaded())
|
||||||
|
return BytesContainer();
|
||||||
ScopeLock lock(Locker);
|
ScopeLock lock(Locker);
|
||||||
|
|
||||||
if (IsVirtual())
|
if (IsVirtual())
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ AssetChunksFlag AnimationGraphFunction::getChunksToPreload() const
|
|||||||
BytesContainer AnimationGraphFunction::LoadSurface() const
|
BytesContainer AnimationGraphFunction::LoadSurface() const
|
||||||
{
|
{
|
||||||
BytesContainer result;
|
BytesContainer result;
|
||||||
|
if (WaitForLoaded())
|
||||||
|
return result;
|
||||||
ScopeLock lock(Locker);
|
ScopeLock lock(Locker);
|
||||||
result.Link(GraphData);
|
result.Link(GraphData);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -431,7 +431,7 @@ void Material::InitCompilationOptions(ShaderCompilationOptions& options)
|
|||||||
options.Macros.Add({ "USE_GBUFFER_CUSTOM_DATA", Numbers[useCustomData ? 1 : 0] });
|
options.Macros.Add({ "USE_GBUFFER_CUSTOM_DATA", Numbers[useCustomData ? 1 : 0] });
|
||||||
options.Macros.Add({ "USE_REFLECTIONS", Numbers[info.FeaturesFlags & MaterialFeaturesFlags::DisableReflections ? 0 : 1] });
|
options.Macros.Add({ "USE_REFLECTIONS", Numbers[info.FeaturesFlags & MaterialFeaturesFlags::DisableReflections ? 0 : 1] });
|
||||||
if (!(info.FeaturesFlags & MaterialFeaturesFlags::DisableReflections) && info.FeaturesFlags & MaterialFeaturesFlags::ScreenSpaceReflections)
|
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] });
|
options.Macros.Add({ "USE_FOG", Numbers[info.FeaturesFlags & MaterialFeaturesFlags::DisableFog ? 0 : 1] });
|
||||||
if (useForward)
|
if (useForward)
|
||||||
options.Macros.Add({ "USE_PIXEL_NORMAL_OFFSET_REFRACTION", Numbers[info.FeaturesFlags & MaterialFeaturesFlags::PixelNormalOffsetRefraction ? 1 : 0] });
|
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 Material::LoadSurface(bool createDefaultIfMissing)
|
||||||
{
|
{
|
||||||
BytesContainer result;
|
BytesContainer result;
|
||||||
|
if (WaitForLoaded())
|
||||||
|
return result;
|
||||||
ScopeLock lock(Locker);
|
ScopeLock lock(Locker);
|
||||||
|
|
||||||
// Check if has that chunk
|
// Check if has that chunk
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ AssetChunksFlag MaterialFunction::getChunksToPreload() const
|
|||||||
BytesContainer MaterialFunction::LoadSurface()
|
BytesContainer MaterialFunction::LoadSurface()
|
||||||
{
|
{
|
||||||
BytesContainer result;
|
BytesContainer result;
|
||||||
|
if (WaitForLoaded())
|
||||||
|
return result;
|
||||||
ScopeLock lock(Locker);
|
ScopeLock lock(Locker);
|
||||||
if (HasChunk(0))
|
if (HasChunk(0))
|
||||||
{
|
{
|
||||||
@@ -89,6 +91,8 @@ BytesContainer MaterialFunction::LoadSurface()
|
|||||||
|
|
||||||
bool MaterialFunction::LoadSurface(MaterialGraph& graph)
|
bool MaterialFunction::LoadSurface(MaterialGraph& graph)
|
||||||
{
|
{
|
||||||
|
if (WaitForLoaded())
|
||||||
|
return true;
|
||||||
ScopeLock lock(Locker);
|
ScopeLock lock(Locker);
|
||||||
if (HasChunk(0))
|
if (HasChunk(0))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2116,6 +2116,8 @@ const VisualScript::Field* VisualScript::FindField(const StringAnsiView& name) c
|
|||||||
|
|
||||||
BytesContainer VisualScript::LoadSurface()
|
BytesContainer VisualScript::LoadSurface()
|
||||||
{
|
{
|
||||||
|
if (WaitForLoaded())
|
||||||
|
return BytesContainer();
|
||||||
ScopeLock lock(Locker);
|
ScopeLock lock(Locker);
|
||||||
if (!LoadChunks(GET_CHUNK_FLAG(0)))
|
if (!LoadChunks(GET_CHUNK_FLAG(0)))
|
||||||
{
|
{
|
||||||
@@ -2124,7 +2126,6 @@ BytesContainer VisualScript::LoadSurface()
|
|||||||
result.Copy(data->Data);
|
result.Copy(data->Data);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(Warning, "\'{0}\' surface data is missing.", ToString());
|
LOG(Warning, "\'{0}\' surface data is missing.", ToString());
|
||||||
return BytesContainer();
|
return BytesContainer();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -335,6 +335,8 @@ void ParticleEmitter::InitCompilationOptions(ShaderCompilationOptions& options)
|
|||||||
BytesContainer ParticleEmitter::LoadSurface(bool createDefaultIfMissing)
|
BytesContainer ParticleEmitter::LoadSurface(bool createDefaultIfMissing)
|
||||||
{
|
{
|
||||||
BytesContainer result;
|
BytesContainer result;
|
||||||
|
if (WaitForLoaded())
|
||||||
|
return result;
|
||||||
ScopeLock lock(Locker);
|
ScopeLock lock(Locker);
|
||||||
|
|
||||||
// Check if has that chunk
|
// Check if has that chunk
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ AssetChunksFlag ParticleEmitterFunction::getChunksToPreload() const
|
|||||||
|
|
||||||
bool ParticleEmitterFunction::LoadSurface(ParticleEmitterGraphCPU& graph)
|
bool ParticleEmitterFunction::LoadSurface(ParticleEmitterGraphCPU& graph)
|
||||||
{
|
{
|
||||||
|
if (WaitForLoaded())
|
||||||
|
return true;
|
||||||
ScopeLock lock(Locker);
|
ScopeLock lock(Locker);
|
||||||
if (HasChunk(0))
|
if (HasChunk(0))
|
||||||
{
|
{
|
||||||
@@ -102,6 +104,8 @@ bool ParticleEmitterFunction::LoadSurface(ParticleEmitterGraphCPU& graph)
|
|||||||
BytesContainer ParticleEmitterFunction::LoadSurface()
|
BytesContainer ParticleEmitterFunction::LoadSurface()
|
||||||
{
|
{
|
||||||
BytesContainer result;
|
BytesContainer result;
|
||||||
|
if (WaitForLoaded())
|
||||||
|
return result;
|
||||||
ScopeLock lock(Locker);
|
ScopeLock lock(Locker);
|
||||||
if (HasChunk(0))
|
if (HasChunk(0))
|
||||||
{
|
{
|
||||||
@@ -118,6 +122,8 @@ BytesContainer ParticleEmitterFunction::LoadSurface()
|
|||||||
|
|
||||||
bool ParticleEmitterFunction::LoadSurface(ParticleEmitterGraphGPU& graph)
|
bool ParticleEmitterFunction::LoadSurface(ParticleEmitterGraphGPU& graph)
|
||||||
{
|
{
|
||||||
|
if (WaitForLoaded())
|
||||||
|
return true;
|
||||||
ScopeLock lock(Locker);
|
ScopeLock lock(Locker);
|
||||||
if (HasChunk(0))
|
if (HasChunk(0))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user