Fix potential incorrect null checks in FlaxEngine.Objects

The null-conditional operator checks for reference equality of the
Object, but doesn't check the validity of the unmanaged pointer. This
check is corrected in cases where the object was not immediately
returned from the bindings layer and may have been destroyed earlier.
This commit is contained in:
2023-09-25 23:06:14 +03:00
parent ea201b6173
commit 58445f04c4
18 changed files with 42 additions and 35 deletions

View File

@@ -37,7 +37,7 @@ namespace FlaxEngine.GUI
}
/// <inheritdoc />
public Float2 Size => Texture?.Size ?? Float2.Zero;
public Float2 Size => Texture != null ? Texture.Size : Float2.Zero;
/// <inheritdoc />
public void Draw(Rectangle rect, Color color)

View File

@@ -104,7 +104,7 @@ namespace FlaxEngine.GUI
}
/// <inheritdoc />
public Float2 Size => Texture?.Size ?? Float2.Zero;
public Float2 Size => Texture != null ? Texture.Size : Float2.Zero;
/// <inheritdoc />
public unsafe void Draw(Rectangle rect, Color color)

View File

@@ -493,7 +493,8 @@ namespace FlaxEngine
if (_renderer)
{
#if FLAX_EDITOR
_editorTask?.RemoveCustomPostFx(_renderer);
if (_editorTask != null)
_editorTask.RemoveCustomPostFx(_renderer);
#endif
SceneRenderTask.RemoveGlobalCustomPostFx(_renderer);
_renderer.Canvas = null;

View File

@@ -204,7 +204,7 @@ namespace FlaxEngine
up = value;
Internal_SetNavTargets(__unmanagedPtr, GetUnmanagedPtr(up), GetUnmanagedPtr(down), GetUnmanagedPtr(left), GetUnmanagedPtr(right));
if (_control != null)
_control.NavTargetUp = value?.Control;
_control.NavTargetUp = value != null ? value.Control : null;
}
}
@@ -228,7 +228,7 @@ namespace FlaxEngine
down = value;
Internal_SetNavTargets(__unmanagedPtr, GetUnmanagedPtr(up), GetUnmanagedPtr(down), GetUnmanagedPtr(left), GetUnmanagedPtr(right));
if (_control != null)
_control.NavTargetDown = value?.Control;
_control.NavTargetDown = value != null ? value.Control : null;
}
}
@@ -252,7 +252,7 @@ namespace FlaxEngine
left = value;
Internal_SetNavTargets(__unmanagedPtr, GetUnmanagedPtr(up), GetUnmanagedPtr(down), GetUnmanagedPtr(left), GetUnmanagedPtr(right));
if (_control != null)
_control.NavTargetLeft = value?.Control;
_control.NavTargetLeft = value != null ? value.Control : null;
}
}
@@ -276,7 +276,7 @@ namespace FlaxEngine
right = value;
Internal_SetNavTargets(__unmanagedPtr, GetUnmanagedPtr(up), GetUnmanagedPtr(down), GetUnmanagedPtr(left), GetUnmanagedPtr(right));
if (_control != null)
_control.NavTargetRight = value?.Control;
_control.NavTargetRight = value != null ? value.Control : null;
}
}