Skip to content

Commit

Permalink
[NUI.Scene3D] Fix exception when ModelNode don't have ModelNode as child
Browse files Browse the repository at this point in the history
If ModelNode don't have ModelNod as child, it might have
some null handle exception when we DownCast to ModelNode.
(For example, user try to get child ModelNode, but failed.)

Currently, a lots of app don't consider ModelNode now. But in future
we might need to add something under each ModelNode.

To make Scene3D more safety, let we check null or invalidate,
and then get/set the value internally.

Signed-off-by: Eunki, Hong <[email protected]>
  • Loading branch information
Eunki, Hong committed Nov 14, 2023
1 parent 08f1eb2 commit c882872
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
20 changes: 15 additions & 5 deletions src/Tizen.NUI.Scene3D/src/public/Controls/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,17 @@ public ModelNode FindChildModelNodeByName(string nodeName)
{
// Store the value of PositionUsesAnchorPoint from dali object (Since View object automatically change PositionUsesPivotPoint value as false, we need to keep value.)
HandleRef handle = new HandleRef(this, cPtr);
bool originalPositionUsesAnchorPoint = Object.InternalGetPropertyBool(handle, View.Property.PositionUsesAnchorPoint);

// Use original value as 'true' if we got invalid ModelNode.
bool originalPositionUsesAnchorPoint = (cPtr == global::System.IntPtr.Zero || !Tizen.NUI.Interop.BaseHandle.HasBody(handle)) || Object.InternalGetPropertyBool(handle, View.Property.PositionUsesAnchorPoint);
handle = new HandleRef(null, IntPtr.Zero);

// Register new animatable into Registry.
ret = new ModelNode(cPtr, true);
ret.PositionUsesPivotPoint = originalPositionUsesAnchorPoint;
if (ret != null)
{
ret.PositionUsesPivotPoint = originalPositionUsesAnchorPoint;
}
}
else
{
Expand Down Expand Up @@ -585,12 +590,17 @@ private ModelNode GetModelRoot()
{
// Store the value of PositionUsesAnchorPoint from dali object (Since View object automatically change PositionUsesPivotPoint value as false, we need to keep value.)
HandleRef handle = new HandleRef(this, cPtr);
bool originalPositionUsesAnchorPoint = Object.InternalGetPropertyBool(handle, View.Property.PositionUsesAnchorPoint);

// Use original value as 'true' if we got invalid ModelNode.
bool originalPositionUsesAnchorPoint = (cPtr == global::System.IntPtr.Zero || !Tizen.NUI.Interop.BaseHandle.HasBody(handle)) || Object.InternalGetPropertyBool(handle, View.Property.PositionUsesAnchorPoint);
handle = new HandleRef(null, IntPtr.Zero);

// Register new animatable into Registry.
ret = new ModelNode(cPtr, true);
ret.PositionUsesPivotPoint = originalPositionUsesAnchorPoint;
if (ret != null)
{
ret.PositionUsesPivotPoint = originalPositionUsesAnchorPoint;
}
}
else
{
Expand Down Expand Up @@ -626,7 +636,7 @@ private float GetImageBasedLightScaleFactor()

private void OnResourcesLoaded(object sender, EventArgs e)
{
if(!isBuilt && this.ModelRoot != null)
if (!isBuilt && this.ModelRoot != null)
{
this.ModelRoot.Build();
isBuilt = true;
Expand Down
29 changes: 21 additions & 8 deletions src/Tizen.NUI.Scene3D/src/public/ModelComponents/ModelNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,17 @@ public ModelNode FindChildModelNodeByName(string nodeName)
{
// Store the value of PositionUsesAnchorPoint from dali object (Since View object automatically change PositionUsesPivotPoint value as false, we need to keep value.)
HandleRef handle = new HandleRef(this, cPtr);
bool originalPositionUsesAnchorPoint = Object.InternalGetPropertyBool(handle, View.Property.PositionUsesAnchorPoint);

// Use original value as 'true' if we got invalid ModelNode.
bool originalPositionUsesAnchorPoint = (cPtr == global::System.IntPtr.Zero || !Tizen.NUI.Interop.BaseHandle.HasBody(handle)) || Object.InternalGetPropertyBool(handle, View.Property.PositionUsesAnchorPoint);
handle = new HandleRef(null, IntPtr.Zero);

// Register new animatable into Registry.
ret = new ModelNode(cPtr, true);
ret.PositionUsesPivotPoint = originalPositionUsesAnchorPoint;
if (ret != null)
{
ret.PositionUsesPivotPoint = originalPositionUsesAnchorPoint;
}
}
else
{
Expand Down Expand Up @@ -219,14 +224,17 @@ internal void Build()
{
List<ModelNode> childModelNodes = new List<ModelNode>();
uint childModelNodeCount = GetChildModelNodeCount();
for(uint i = 0; i < childModelNodeCount; ++i)
for (uint i = 0; i < childModelNodeCount; ++i)
{
ModelNode modelNode = GetChildModelNodeAt(i);
childModelNodes.Add(modelNode);
modelNode.Build();
if (modelNode != null)
{
childModelNodes.Add(modelNode);
modelNode.Build();
}
}

foreach(ModelNode node in childModelNodes)
foreach (ModelNode node in childModelNodes)
{
this.Add(node);
}
Expand Down Expand Up @@ -260,12 +268,17 @@ private ModelNode GetChildModelNodeAt(uint index)
{
// Store the value of PositionUsesAnchorPoint from dali object (Since View object automatically change PositionUsesPivotPoint value as false, we need to keep value.)
HandleRef handle = new HandleRef(this, cPtr);
bool originalPositionUsesAnchorPoint = Object.InternalGetPropertyBool(handle, View.Property.PositionUsesAnchorPoint);

// Use original value as 'true' if we got invalid ModelNode.
bool originalPositionUsesAnchorPoint = (cPtr == global::System.IntPtr.Zero || !Tizen.NUI.Interop.BaseHandle.HasBody(handle)) || Object.InternalGetPropertyBool(handle, View.Property.PositionUsesAnchorPoint);
handle = new HandleRef(null, IntPtr.Zero);

// Register new animatable into Registry.
ret = new ModelNode(cPtr, true);
ret.PositionUsesPivotPoint = originalPositionUsesAnchorPoint;
if (ret != null)
{
ret.PositionUsesPivotPoint = originalPositionUsesAnchorPoint;
}
}
else
{
Expand Down

0 comments on commit c882872

Please sign in to comment.