From 4a7f1a5fde285daba16e2038a3207b33a6827eb7 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 6 Feb 2026 10:37:52 +0100 Subject: [PATCH] Fix various issues --- .../Windows/Assets/AnimationGraphWindow.cs | 9 +++- Source/Engine/Foliage/Foliage.cpp | 4 +- Source/Engine/Foliage/FoliageCluster.cpp | 45 ++++++++++--------- Source/Engine/Level/Actor.cpp | 4 +- Source/Engine/Threading/JobSystem.cpp | 2 - 5 files changed, 37 insertions(+), 27 deletions(-) diff --git a/Source/Editor/Windows/Assets/AnimationGraphWindow.cs b/Source/Editor/Windows/Assets/AnimationGraphWindow.cs index 7e809d968..12142219c 100644 --- a/Source/Editor/Windows/Assets/AnimationGraphWindow.cs +++ b/Source/Editor/Windows/Assets/AnimationGraphWindow.cs @@ -99,7 +99,14 @@ namespace FlaxEditor.Windows.Assets Window = window; var surfaceParam = window.Surface.GetParameter(BaseModelId); if (surfaceParam != null) - BaseModel = FlaxEngine.Content.LoadAsync((Guid)surfaceParam.Value); + { + if (surfaceParam.Value is Guid asGuid) + BaseModel = FlaxEngine.Content.LoadAsync(asGuid); + else if (surfaceParam.Value is SkinnedModel asModel) + BaseModel = asModel; + else + BaseModel = null; + } else BaseModel = window.PreviewActor.GetParameterValue(BaseModelId) as SkinnedModel; } diff --git a/Source/Engine/Foliage/Foliage.cpp b/Source/Engine/Foliage/Foliage.cpp index 6d3d8b700..116866848 100644 --- a/Source/Engine/Foliage/Foliage.cpp +++ b/Source/Engine/Foliage/Foliage.cpp @@ -41,8 +41,7 @@ Foliage::Foliage(const SpawnParams& params) void Foliage::AddToCluster(ChunkedArray& clusters, FoliageCluster* cluster, FoliageInstance& instance) { - ASSERT(instance.Bounds.Radius > ZeroTolerance); - ASSERT(cluster->Bounds.Intersects(instance.Bounds)); + ASSERT_LOW_LAYER(instance.Bounds.Radius > ZeroTolerance); // Minor clusters don't use bounds intersection but try to find the first free cluster instead if (cluster->IsMinor) @@ -63,6 +62,7 @@ void Foliage::AddToCluster(ChunkedArrayBounds.Intersects(instance.Bounds)); while (cluster->Children[0]) { #define CHECK_CHILD(idx) \ diff --git a/Source/Engine/Foliage/FoliageCluster.cpp b/Source/Engine/Foliage/FoliageCluster.cpp index fd4c0f753..107bf265a 100644 --- a/Source/Engine/Foliage/FoliageCluster.cpp +++ b/Source/Engine/Foliage/FoliageCluster.cpp @@ -21,26 +21,7 @@ void FoliageCluster::Init(const BoundingBox& bounds) void FoliageCluster::UpdateTotalBoundsAndCullDistance() { - if (Children[0]) - { - ASSERT(Instances.IsEmpty()); - - Children[0]->UpdateTotalBoundsAndCullDistance(); - Children[1]->UpdateTotalBoundsAndCullDistance(); - Children[2]->UpdateTotalBoundsAndCullDistance(); - Children[3]->UpdateTotalBoundsAndCullDistance(); - - TotalBounds = Children[0]->TotalBounds; - BoundingBox::Merge(TotalBounds, Children[1]->TotalBounds, TotalBounds); - BoundingBox::Merge(TotalBounds, Children[2]->TotalBounds, TotalBounds); - BoundingBox::Merge(TotalBounds, Children[3]->TotalBounds, TotalBounds); - - MaxCullDistance = Children[0]->MaxCullDistance; - MaxCullDistance = Math::Max(MaxCullDistance, Children[1]->MaxCullDistance); - MaxCullDistance = Math::Max(MaxCullDistance, Children[2]->MaxCullDistance); - MaxCullDistance = Math::Max(MaxCullDistance, Children[3]->MaxCullDistance); - } - else if (Instances.HasItems()) + if (Instances.HasItems()) { BoundingBox box; BoundingBox::FromSphere(Instances[0]->Bounds, TotalBounds); @@ -58,6 +39,30 @@ void FoliageCluster::UpdateTotalBoundsAndCullDistance() MaxCullDistance = 0; } + if (Children[0]) + { + Children[0]->UpdateTotalBoundsAndCullDistance(); + Children[1]->UpdateTotalBoundsAndCullDistance(); + Children[2]->UpdateTotalBoundsAndCullDistance(); + Children[3]->UpdateTotalBoundsAndCullDistance(); + + if (Instances.HasItems()) + BoundingBox::Merge(TotalBounds, Children[0]->TotalBounds, TotalBounds); + else + TotalBounds = Children[0]->TotalBounds; + BoundingBox::Merge(TotalBounds, Children[1]->TotalBounds, TotalBounds); + BoundingBox::Merge(TotalBounds, Children[2]->TotalBounds, TotalBounds); + BoundingBox::Merge(TotalBounds, Children[3]->TotalBounds, TotalBounds); + + if (Instances.HasItems()) + MaxCullDistance = Math::Max(MaxCullDistance, Children[0]->MaxCullDistance); + else + MaxCullDistance = Children[0]->MaxCullDistance; + MaxCullDistance = Math::Max(MaxCullDistance, Children[1]->MaxCullDistance); + MaxCullDistance = Math::Max(MaxCullDistance, Children[2]->MaxCullDistance); + MaxCullDistance = Math::Max(MaxCullDistance, Children[3]->MaxCullDistance); + } + BoundingSphere::FromBox(TotalBounds, TotalBoundsSphere); } diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp index 7d07cd0e7..f52fab600 100644 --- a/Source/Engine/Level/Actor.cpp +++ b/Source/Engine/Level/Actor.cpp @@ -1685,7 +1685,7 @@ Quaternion Actor::LookingAt(const Vector3& worldPos) const { const Vector3 direction = worldPos - _transform.Translation; if (direction.LengthSquared() < ZeroTolerance) - return _parent->GetOrientation(); + return _parent ? _parent->GetOrientation() : Quaternion::Identity; const Float3 newForward = Vector3::Normalize(direction); const Float3 oldForward = _transform.Orientation * Vector3::Forward; @@ -1712,7 +1712,7 @@ Quaternion Actor::LookingAt(const Vector3& worldPos, const Vector3& worldUp) con { const Vector3 direction = worldPos - _transform.Translation; if (direction.LengthSquared() < ZeroTolerance) - return _parent->GetOrientation(); + return _parent ? _parent->GetOrientation() : Quaternion::Identity; const Float3 forward = Vector3::Normalize(direction); const Float3 up = Vector3::Normalize(worldUp); if (Math::IsOne(Float3::Dot(forward, up))) diff --git a/Source/Engine/Threading/JobSystem.cpp b/Source/Engine/Threading/JobSystem.cpp index cbdf53136..4d90f1c06 100644 --- a/Source/Engine/Threading/JobSystem.cpp +++ b/Source/Engine/Threading/JobSystem.cpp @@ -317,7 +317,6 @@ int64 JobSystem::Dispatch(const Function& job, int32 jobCount) context.DependantsCount = 0; context.DependenciesLeft = 0; context.JobsCount = jobCount; - ASSERT(context.Dependants.IsEmpty()); context.Dependants.Clear(); // Move the job queue forward @@ -367,7 +366,6 @@ int64 JobSystem::Dispatch(const Function& job, Span dependen context.DependantsCount = 0; context.DependenciesLeft = 0; context.JobsCount = jobCount; - ASSERT(context.Dependants.IsEmpty()); context.Dependants.Clear(); { JobsLocker.Lock();