Skip to content

Commit

Permalink
修正 dispose 的调用时机,确保脚本层的出发顺序时正确的
Browse files Browse the repository at this point in the history
  • Loading branch information
Geequlim committed Jul 11, 2024
1 parent 024fc72 commit 5cc542c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
33 changes: 17 additions & 16 deletions Assets/Scripts/UI/GComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ override protected void CreateDisplayObject()

override public void Dispose()
{

#if FAIRYGUI_TOLUA
if (_peerTable != null)
{
_peerTable.Dispose();
_peerTable = null;
}
#endif

#if FAIRYGUI_PUERTS
if (__onDispose != null)
__onDispose();
__onConstruct = null;
__onDispose = null;
#endif

int cnt = _transitions.Count;
for (int i = 0; i < cnt; ++i)
{
Expand All @@ -83,8 +99,6 @@ override public void Dispose()
if (scrollPane != null)
scrollPane.Dispose();

base.Dispose(); //Dispose native tree first, avoid DisplayObject.RemoveFromParent call

cnt = _children.Count;
for (int i = cnt - 1; i >= 0; --i)
{
Expand All @@ -93,20 +107,7 @@ override public void Dispose()
obj.Dispose();
}

#if FAIRYGUI_TOLUA
if (_peerTable != null)
{
_peerTable.Dispose();
_peerTable = null;
}
#endif

#if FAIRYGUI_PUERTS
if (__onDispose != null)
__onDispose();
__onConstruct = null;
__onDispose = null;
#endif
base.Dispose(); //Dispose native tree first, avoid DisplayObject.RemoveFromParent call
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/UI/GGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public void SetNativeObject(DisplayObject obj)
_shape = null;
}

if (displayObject != null) displayObject.Dispose();
displayObject = obj;

if (displayObject != null)
Expand Down

0 comments on commit 5cc542c

Please sign in to comment.