From: Eunki, Hong Date: Wed, 16 Mar 2022 06:56:09 +0000 (+0900) Subject: [NUI] Fix crash issue when visual create failed X-Git-Tag: accepted/tizen/unified/20231205.024657~1119 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6194238e5aa0ba00d3ed815989d55d64a5dde2d3;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Fix crash issue when visual create failed Due to the empty array issue, we change that we don't create visual when UrlList is empty. But current NUI.VisualView don't consider that visual failure case. This patch consider case when we fail to create visual, so visual is null in VisualView. TODO : need to make TCT Signed-off-by: Eunki, Hong --- diff --git a/src/Tizen.NUI/src/public/BaseComponents/VisualView.cs b/src/Tizen.NUI/src/public/BaseComponents/VisualView.cs index 103593d..7657a9a 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/VisualView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/VisualView.cs @@ -42,7 +42,7 @@ namespace Tizen.NUI.BaseComponents /// 3 public class VisualView : CustomView { - //private LinkedList _visualList = null; + private Dictionary visualNameDictionary = null; private Dictionary visualDictionary = null; private Dictionary tranformDictionary = null; private PropertyArray animateArray = null; @@ -106,6 +106,7 @@ namespace Tizen.NUI.BaseComponents base.OnInitialize(); //Initialize empty + visualNameDictionary = new Dictionary(); visualDictionary = new Dictionary(); tranformDictionary = new Dictionary(); animateArray = new PropertyArray(); @@ -120,18 +121,18 @@ namespace Tizen.NUI.BaseComponents /// 3 public void AddVisual(string visualName, VisualMap visualMap) { - VisualBase visual = null; int visualIndex = -1; /* If the visual had added, then replace it using RegisterVusal. */ //visual.Name = name; - foreach (var item in visualDictionary) + foreach (var item in visualNameDictionary) { - if (item.Value.Name == visualName) + if (item.Value == visualName) { /* Find a existed visual, its key also exited. */ visualIndex = item.Key; UnregisterVisual(visualIndex); + visualNameDictionary.Remove(visualIndex); visualDictionary.Remove(visualIndex); tranformDictionary.Remove(visualIndex); break; @@ -152,20 +153,13 @@ namespace Tizen.NUI.BaseComponents { throw new ArgumentNullException(nameof(visualMap)); } - visual = VisualFactory.Instance.CreateVisual(visualMap.OutputVisualMap); // Create a visual for the new one. - visual.Name = visualName; - visual.DepthIndex = visualMap.DepthIndex; - - RegisterVisual(visualIndex, visual); - - visualDictionary.Add(visualIndex, visual); - tranformDictionary.Add(visualIndex, visualMap.OutputTransformMap); visualMap.VisualIndex = visualIndex; visualMap.Name = visualName; visualMap.Parent = this; - RelayoutRequest(); + // Register index and name + UpdateVisual(visualIndex, visualName, visualMap); } } @@ -176,14 +170,15 @@ namespace Tizen.NUI.BaseComponents /// 3 public void RemoveVisual(string visualName) { - foreach (var item in visualDictionary) + foreach (var item in visualNameDictionary) { - if (item.Value.Name == visualName) + if (item.Value == visualName) { EnableVisual(item.Key, false); UnregisterVisual(item.Key); tranformDictionary.Remove(item.Key); visualDictionary.Remove(item.Key); + visualNameDictionary.Remove(item.Key); RelayoutRequest(); break; @@ -197,13 +192,14 @@ namespace Tizen.NUI.BaseComponents /// 3 public void RemoveAll() { - foreach (var item in visualDictionary) + foreach (var item in visualNameDictionary) { EnableVisual(item.Key, false); UnregisterVisual(item.Key); } visualDictionary.Clear(); tranformDictionary.Clear(); + visualNameDictionary.Clear(); RelayoutRequest(); } @@ -221,8 +217,11 @@ namespace Tizen.NUI.BaseComponents { foreach (var item in visualDictionary) { - item.Value.SetTransformAndSize(tranformDictionary[item.Key], size); - EnableVisual(item.Key, true); + if(item.Value != null) + { + item.Value.SetTransformAndSize(tranformDictionary[item.Key], size); + EnableVisual(item.Key, true); + } } } @@ -248,9 +247,9 @@ namespace Tizen.NUI.BaseComponents string strAlpha = alphaFunction?.GetDescription(); - foreach (var item in visualDictionary.ToList()) + foreach (var item in visualNameDictionary.ToList()) { - if (item.Value.Name == target.Name) + if (item.Value == target.Name) { using (PropertyMap animator = new PropertyMap()) using (PropertyMap timePeriod = new PropertyMap()) @@ -330,9 +329,9 @@ namespace Tizen.NUI.BaseComponents string strAlpha = alphaFunction?.GetDescription(); - foreach (var item in visualDictionary.ToList()) + foreach (var item in visualNameDictionary.ToList()) { - if (item.Value.Name == target.Name) + if (item.Value == target.Name) { using (PropertyMap animator = new PropertyMap()) using (PropertyMap timePeriod = new PropertyMap()) @@ -422,9 +421,9 @@ namespace Tizen.NUI.BaseComponents throw new ArgumentNullException(nameof(visualMap)); } - foreach (var item in visualDictionary.ToList()) + foreach (var item in visualNameDictionary.ToList()) { - if (item.Value.Name == visualMap.Target) + if (item.Value == visualMap.Target) { using (TransitionData transitionData = new TransitionData(visualMap.OutputVisualMap)) { @@ -438,19 +437,26 @@ namespace Tizen.NUI.BaseComponents internal void UpdateVisual(int visualIndex, string visualName, VisualMap visualMap) { - VisualBase visual = null; - - visual = VisualFactory.Instance.CreateVisual(visualMap.OutputVisualMap); - visual.Name = visualName; - visual.DepthIndex = visualMap.DepthIndex; - - RegisterVisual(visualIndex, visual); + VisualBase visual = VisualFactory.Instance.CreateVisual(visualMap.OutputVisualMap); + visualNameDictionary[visualIndex] = visualName; visualDictionary[visualIndex] = visual; tranformDictionary[visualIndex] = visualMap.OutputTransformMap; - RelayoutRequest(); - NUILog.Debug("UpdateVisual() name=" + visualName); + if(visual != null) + { + visual.Name = visualName; + visual.DepthIndex = visualMap.DepthIndex; + + RegisterVisual(visualIndex, visual); + + RelayoutRequest(); + NUILog.Debug("UpdateVisual() name=" + visualName); + } + else + { + NUILog.Debug("UpdateVisual() FAIL! visual create failed name=" + visualName); + } } static CustomView CreateInstance()