Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NUI] Temperary revert exception throw at Registry. #5667

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions src/Tizen.NUI/src/internal/Common/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,44 +61,55 @@ internal static void Register(BaseHandle baseHandle)
if (Instance._controlMap.TryAdd(refCptr, new WeakReference(baseHandle, true)) != true)
{
WeakReference weakReference;
if(Instance._controlMap.TryGetValue(refCptr, out weakReference))
if (Instance._controlMap.TryGetValue(refCptr, out weakReference))
{
if (weakReference == null)
{
Tizen.Log.Error("NUI", $"Something Wrong! weakReference is null\n");
throw new System.InvalidOperationException("Error! NUI Registry weakReference should not be NULL!");
Tizen.Log.Error("NUI", $"Something Wrong! weakReference is null! input type:{baseHandle.GetType()}\n");

// 2023-10-30 : Just print error log without exception. Please reopne below throw action after all apps fixed.
Tizen.Log.Fatal("NUI", "Error! just return here without Register! this can cause unknown error or crash in next step");
return;
//throw new System.InvalidOperationException("Error! NUI Registry weakReference should not be NULL!");
}
var target = weakReference.Target;

BaseHandle ret = target as BaseHandle;
if (ret != null)
{
Tizen.Log.Error("NUI", $"refCptr is already exist! input type:{baseHandle.GetType()}, registed type:{ret.GetType()}, refCptr:{refCptr.ToString("X8")}\n");
throw new System.InvalidOperationException("refCptr is already exist!");
}
else if(target == null)
if (target == null)
{
// Special case. If WeakReference.Target is null, it might be disposed by GC. just Add forcely.
if (Instance._controlMap.TryRemove(refCptr, out weakReference) != true)
{
Tizen.Log.Error("NUI", $"Something Wrong when we try to remove null target\n");
Tizen.Log.Error("NUI", $"Something Wrong when we try to remove null target! input type:{baseHandle.GetType()}, registed type:{target?.GetType()}\n");
}
if (Instance._controlMap.TryAdd(refCptr, new WeakReference(baseHandle, false)) != true)
{
Tizen.Log.Error("NUI", $"Something Wrong when we try to replace null target\n");
throw new System.InvalidOperationException("refCptr register failed");
Tizen.Log.Error("NUI", $"Something Wrong when we try to replace null target! input type:{baseHandle.GetType()}, registed type:{target?.GetType()}\n");

// 2023-10-30 : Just print error log without exception. Please reopne below throw action after all apps fixed.
Tizen.Log.Fatal("NUI", "Error! just return here without Register! this can cause unknown error or crash in next step");
return;
//throw new System.InvalidOperationException("refCptr register failed");
}
}
else
{
Tizen.Log.Error("NUI", $"Something Wrong!! target is not BaseHandle! target.GetType() : {target?.GetType()}\n");
throw new System.InvalidOperationException("refCptr is already exist, but not a BaseHandle!");
Tizen.Log.Error("NUI", $"Something Wrong!! refCptr is already exist! input type:{baseHandle.GetType()}, registed type:{target?.GetType()}, refCptr:{refCptr.ToString("X8")}\n");

// 2023-10-30 : Just print error log without exception. Please reopne below throw action after all apps fixed.
Tizen.Log.Fatal("NUI", "Error! just return here without Register! this can cause unknown error or crash in next step");
return;
//throw new System.InvalidOperationException("refCptr is already exist!");
}
}
else
{
Tizen.Log.Error("NUI", $"refCptr is already exist! OR something Wrong!!!\n");
throw new System.InvalidOperationException("refCptr is already exist, but fail to get handle!");
Tizen.Log.Error("NUI", $"refCptr is already exist! OR something Wrong!!! input type:{baseHandle.GetType()}\n");

// 2023-10-30 : Just print error log without exception. Please reopne below throw action after all apps fixed.
Tizen.Log.Fatal("NUI", "Error! just return here without Register! this can cause unknown error or crash in next step");
return;
//throw new System.InvalidOperationException("refCptr is already exist, but fail to get handle!");
}
}

Expand All @@ -118,7 +129,7 @@ internal static void Unregister(BaseHandle baseHandle)
WeakReference refe;
if (Instance._controlMap.TryRemove(refCptr, out refe) != true)
{
NUILog.Debug("something wrong when removing refCptr!");
Tizen.Log.Error("NUI", $"something wrong when removing refCptr!\n");
}

NUILog.Debug($"[Registry] Unregister! type:{baseHandle.GetType()} count:{Instance._controlMap.Count} copyNativeHandle:{baseHandle.GetBaseHandleCPtrHandleRef.Handle.ToString("X8")}");
Expand Down