Skip to content

Commit bdb9a4a

Browse files
authored
fix: Crash when adding bepu's DebugRenderComponent in editor (#3050)
1 parent adea5ef commit bdb9a4a

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

sources/engine/Stride.BepuPhysics/Stride.BepuPhysics.Debug/DebugRenderProcessor.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public bool Visible
3636
get => _visible;
3737
set
3838
{
39-
if (_sceneSystem.SceneInstance.GetProcessor<CollidableProcessor>() is { } proc)
39+
if (_sceneSystem.SceneInstance.GetProcessor<CollidableProcessor>() is { } proc && _visibilityGroup is not null)
4040
{
4141
if (_visible == value)
4242
return;
@@ -66,7 +66,7 @@ public bool Visible
6666
protected override void OnEntityComponentAdding(Entity entity, DebugRenderComponent component, DebugRenderComponent data)
6767
{
6868
base.OnEntityComponentAdding(entity, component, data);
69-
if (_sceneSystem.SceneInstance.GetProcessor<CollidableProcessor>() is not null)
69+
if (_sceneSystem?.SceneInstance?.GetProcessor<CollidableProcessor>() is not null && _visibilityGroup is not null)
7070
Visible = component.Visible;
7171
else if (component.Visible)
7272
_latent = true;
@@ -76,19 +76,9 @@ protected override void OnEntityComponentAdding(Entity entity, DebugRenderCompon
7676

7777
protected override void OnSystemAdd()
7878
{
79-
SinglePassWireframeRenderFeature wireframeRenderFeature;
80-
8179
_shapeCacheSystem = Services.GetOrCreate<ShapeCacheSystem>();
8280
_game = Services.GetSafeServiceAs<IGame>();
8381
_sceneSystem = Services.GetSafeServiceAs<SceneSystem>();
84-
85-
if (_sceneSystem.GraphicsCompositor.RenderFeatures.OfType<SinglePassWireframeRenderFeature>().FirstOrDefault() is null)
86-
{
87-
wireframeRenderFeature = new();
88-
_sceneSystem.GraphicsCompositor.RenderFeatures.Add(wireframeRenderFeature);
89-
}
90-
91-
_visibilityGroup = _sceneSystem.SceneInstance.VisibilityGroups.First();
9282
}
9383

9484
protected override void OnSystemRemove()
@@ -98,6 +88,18 @@ protected override void OnSystemRemove()
9888

9989
public override void Draw(RenderContext context)
10090
{
91+
if (_visibilityGroup is null)
92+
{
93+
if (_sceneSystem.SceneInstance.VisibilityGroups.Count == 0)
94+
return;
95+
96+
_visibilityGroup = _sceneSystem.SceneInstance.VisibilityGroups.First();
97+
if (_sceneSystem.GraphicsCompositor.RenderFeatures.OfType<SinglePassWireframeRenderFeature>().FirstOrDefault() is null)
98+
{
99+
_sceneSystem.GraphicsCompositor.RenderFeatures.Add(new SinglePassWireframeRenderFeature());
100+
}
101+
}
102+
101103
if (_latent)
102104
{
103105
Visible = true;

0 commit comments

Comments
 (0)