Tencent / puerts

PUER(普洱) Typescript. Let's write your game in UE or Unity with TypeScript.
Other
5.09k stars 709 forks source link

[Unity][Bug] 函数在C#侧和Js侧进行递归调用的时候, 函数参数获取错误 #210

Closed UpUpLiu closed 3 years ago

UpUpLiu commented 3 years ago

引擎: Unity 系统: mac Unity版本: 2019.4.15 Bug描述: 如果一个函数递归在C#侧和 js侧调用. 参数获取有问题. Puerts版本: Tag:v1.0.13,Plugin_Version:11 函数A: image

函数B: image

函数A和函数B 的输出应该是一致的.

image

UpUpLiu commented 3 years ago

会出现错误的调用堆栈: 初始化: UIKitchen_WorkSpace, js_workspace, 当前帧数: 147 UnityEngine.Debug:LogError(Object) ETModel.Js.JsComponent:Init() (at Assets/Scripts/Js/JsComponent.cs:64) ETModel.APIHelper:InitJsComponentData(GameObject) (at Assets/Scripts/Js/APIHelper.cs:165) System.Reflection.MethodBase:Invoke(Object, Object[]) Puerts.OverloadReflectionWrap:Invoke(CallInfo) (at Assets/Libraries/Src/MethodReflection.cs:270) Puerts.MethodReflectionWrap:Invoke(IntPtr, IntPtr, IntPtr, Int32) (at Assets/Libraries/Src/MethodReflection.cs:348) Puerts.JsEnv:InvokeCallback(IntPtr, Int32, IntPtr, IntPtr, Int32) (at Assets/Libraries/Src/JsEnv.cs:236) Puerts.StaticCallbacks:JsEnvCallbackWrap(IntPtr, IntPtr, IntPtr, Int32, Int64) (at Assets/Libraries/Src/StaticCallbacks.cs:21) Puerts.PuertsDLL:InvokeJSFunction(IntPtr, Boolean) Puerts.GenericDelegate:Action(String, GameObject) (at Assets/Libraries/Src/GenericDelegate.cs:478) ETModel.Js.JsComponent:Init() (at Assets/Scripts/Js/JsComponent.cs:65) ETModel.APIHelper:InitJsComponentData(GameObject) (at Assets/Scripts/Js/APIHelper.cs:165) System.Reflection.MethodBase:Invoke(Object, Object[]) Puerts.OverloadReflectionWrap:Invoke(CallInfo) (at Assets/Libraries/Src/MethodReflection.cs:270) Puerts.MethodReflectionWrap:Invoke(IntPtr, IntPtr, IntPtr, Int32) (at Assets/Libraries/Src/MethodReflection.cs:348) Puerts.JsEnv:InvokeCallback(IntPtr, Int32, IntPtr, IntPtr, Int32) (at Assets/Libraries/Src/JsEnv.cs:236) Puerts.StaticCallbacks:JsEnvCallbackWrap(IntPtr, IntPtr, IntPtr, Int32, Int64) (at Assets/Libraries/Src/StaticCallbacks.cs:21) Puerts.PuertsDLL:InvokeJSFunction(IntPtr, Boolean) Puerts.GenericDelegate:Action(String, GameObject) (at Assets/Libraries/Src/GenericDelegate.cs:478) ETModel.Js.JsComponent:Init() (at Assets/Scripts/Js/JsComponent.cs:65) ETModel.APIHelper:InitJsComponentData(GameObject) (at Assets/Scripts/Js/APIHelper.cs:165) System.Reflection.MethodBase:Invoke(Object, Object[]) Puerts.OverloadReflectionWrap:Invoke(CallInfo) (at Assets/Libraries/Src/MethodReflection.cs:270) Puerts.MethodReflectionWrap:Invoke(IntPtr, IntPtr, IntPtr, Int32) (at Assets/Libraries/Src/MethodReflection.cs:348) Puerts.JsEnv:InvokeCallback(IntPtr, Int32, IntPtr, IntPtr, Int32) (at Assets/Libraries/Src/JsEnv.cs:236) Puerts.StaticCallbacks:JsEnvCallbackWrap(IntPtr, IntPtr, IntPtr, Int32, Int64) (at Assets/Libraries/Src/StaticCallbacks.cs:21) Puerts.PuertsDLL:InvokeJSFunction(IntPtr, Boolean) Puerts.GenericDelegate:Action(String, GameObject) (at Assets/Libraries/Src/GenericDelegate.cs:478) ETModel.Js.JsComponent:Init() (at Assets/Scripts/Js/JsComponent.cs:65) ETModel.APIHelper:InitJsComponentData(GameObject) (at Assets/Scripts/Js/APIHelper.cs:165) System.Reflection.MethodBase:Invoke(Object, Object[]) Puerts.OverloadReflectionWrap:Invoke(CallInfo) (at Assets/Libraries/Src/MethodReflection.cs:270) Puerts.MethodReflectionWrap:Invoke(IntPtr, IntPtr, IntPtr, Int32) (at Assets/Libraries/Src/MethodReflection.cs:348) Puerts.JsEnv:InvokeCallback(IntPtr, Int32, IntPtr, IntPtr, Int32) (at Assets/Libraries/Src/JsEnv.cs:236) Puerts.StaticCallbacks:JsEnvCallbackWrap(IntPtr, IntPtr, IntPtr, Int32, Int64) (at Assets/Libraries/Src/StaticCallbacks.cs:21) Puerts.PuertsDLL:InvokeJSFunction(IntPtr, Boolean) Puerts.GenericDelegate:Action(String, GameObject) (at Assets/Libraries/Src/GenericDelegate.cs:478) ETModel.Js.JsComponent:Init() (at Assets/Scripts/Js/JsComponent.cs:65) ETModel.Js.JsComponent:Awake() (at Assets/Scripts/Js/JsComponent.cs:52) UnityEngine.Object:Instantiate(GameObject) ETModel.Res.AssetInfo:Instantiate(Boolean) (at Assets/Scripts/Core/Res/AssetInfo/AssetInfo.cs:256) ETModel.Res.AssetInfo:Instantiate() (at Assets/Scripts/Core/Res/AssetInfo/AssetInfo.cs:217) System.Reflection.MethodBase:Invoke(Object, Object[]) Puerts.OverloadReflectionWrap:Invoke(CallInfo) (at Assets/Libraries/Src/MethodReflection.cs:270) Puerts.MethodReflectionWrap:Invoke(IntPtr, IntPtr, IntPtr, Int32) (at Assets/Libraries/Src/MethodReflection.cs:348) Puerts.JsEnv:InvokeCallback(IntPtr, Int32, IntPtr, IntPtr, Int32) (at Assets/Libraries/Src/JsEnv.cs:236) Puerts.StaticCallbacks:JsEnvCallbackWrap(IntPtr, IntPtr, IntPtr, Int32, Int64) (at Assets/Libraries/Src/StaticCallbacks.cs:21) Puerts.PuertsDLL:InvokeJSFunction(IntPtr, Boolean) Puerts.GenericDelegate:Action(AssetInfo) (at Assets/Libraries/Src/GenericDelegate.cs:459) ETModel.Res.AssetInfo:OnCompleted(AsyncOperationHandle) (at Assets/Scripts/Core/Res/AssetInfo/AssetInfo.cs:171) UnityEngine.ResourceManagement.AsyncOperations.<>cDisplayClass58_0:b0(AsyncOperationHandle1) DelegateList1:Invoke(AsyncOperationHandle1) (at Library/PackageCache/com.unity.addressables@1.17.6-preview/Runtime/ResourceManager/Util/DelegateList.cs:69) UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle:WaitForCompletion() ETModel.Res.AssetInfo:OnStartLoad() (at Assets/Scripts/Core/Res/AssetInfo/AssetInfo.cs:161) ETModel.Res.AssetInfo:StartLoad(Action1) (at Assets/Scripts/Core/Res/AssetInfo/AssetInfo.cs:122) ETModel.Res.AssetManager:LoadAsync(AssetInfo) (at Assets/Scripts/Core/Res/AssetManager.Load.cs:107) ETModel.Res.AssetManager:LoadSync(AssetInfo) (at Assets/Scripts/Core/Res/AssetManager.Load.cs:98) ETModel.Res.AssetManager:StartLoad(AssetInfo) (at Assets/Scripts/Core/Res/AssetManager.Load.cs:152) ETModel.Res.AssetManager:LoadAssetSync(String, LoadType, Action1) (at Assets/Scripts/Core/Res/AssetManager.Load.cs:188) ETModel.APIHelper:GetAsset(String, LoadType, Action1) (at Assets/Scripts/Core/Res/LuaHelper.AAS.cs:32) System.Reflection.MethodBase:Invoke(Object, Object[]) Puerts.OverloadReflectionWrap:Invoke(CallInfo) (at Assets/Libraries/Src/MethodReflection.cs:270) Puerts.MethodReflectionWrap:Invoke(IntPtr, IntPtr, IntPtr, Int32) (at Assets/Libraries/Src/MethodReflection.cs:348) Puerts.JsEnv:InvokeCallback(IntPtr, Int32, IntPtr, IntPtr, Int32) (at Assets/Libraries/Src/JsEnv.cs:236) Puerts.StaticCallbacks:JsEnvCallbackWrap(IntPtr, IntPtr, IntPtr, Int32, Int64) (at Assets/Libraries/Src/StaticCallbacks.cs:21) Puerts.PuertsDLL:InvokeJSFunction(IntPtr, Boolean) Puerts.GenericDelegate:Action(Tab) (at Assets/Libraries/Src/GenericDelegate.cs:459) TabGroup:SetSelected(Tab) (at Assets/Scripts/View/UI/Tab/TabGroup.cs:30) Tab:SetIsOn(Boolean) (at Assets/Scripts/View/UI/Tab/Tab.cs:301) Tab:OnPointerClick(PointerEventData) (at Assets/Scripts/View/UI/Tab/Tab.cs:98) UnityEngine.EventSystems.EventSystem:Update() (at /Applications/Unity/Hub/Editor/2019.4.15f1/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)

UpUpLiu commented 3 years ago

不会出现错误的函数堆栈: 初始化: UILobbyBottomTabGroup, tabGp_BottomTabGroup, 当前帧数: 147 UnityEngine.Debug:LogError(Object) ETModel.Js.JsComponent:Init() (at Assets/Scripts/Js/JsComponent.cs:64) ETModel.Js.JsComponent:Awake() (at Assets/Scripts/Js/JsComponent.cs:52) UnityEngine.Object:Instantiate(GameObject) ETModel.Res.AssetInfo:Instantiate(Boolean) (at Assets/Scripts/Core/Res/AssetInfo/AssetInfo.cs:256) ETModel.Res.AssetInfo:Instantiate() (at Assets/Scripts/Core/Res/AssetInfo/AssetInfo.cs:217) System.Reflection.MethodBase:Invoke(Object, Object[]) Puerts.OverloadReflectionWrap:Invoke(CallInfo) (at Assets/Libraries/Src/MethodReflection.cs:270) Puerts.MethodReflectionWrap:Invoke(IntPtr, IntPtr, IntPtr, Int32) (at Assets/Libraries/Src/MethodReflection.cs:348) Puerts.JsEnv:InvokeCallback(IntPtr, Int32, IntPtr, IntPtr, Int32) (at Assets/Libraries/Src/JsEnv.cs:236) Puerts.StaticCallbacks:JsEnvCallbackWrap(IntPtr, IntPtr, IntPtr, Int32, Int64) (at Assets/Libraries/Src/StaticCallbacks.cs:21) Puerts.PuertsDLL:InvokeJSFunction(IntPtr, Boolean) Puerts.GenericDelegate:Action(AssetInfo) (at Assets/Libraries/Src/GenericDelegate.cs:459) ETModel.Res.AssetInfo:OnCompleted(AsyncOperationHandle) (at Assets/Scripts/Core/Res/AssetInfo/AssetInfo.cs:171) UnityEngine.ResourceManagement.AsyncOperations.<>cDisplayClass58_0:b0(AsyncOperationHandle1) DelegateList1:Invoke(AsyncOperationHandle1) (at Library/PackageCache/com.unity.addressables@1.17.6-preview/Runtime/ResourceManager/Util/DelegateList.cs:69) UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle:WaitForCompletion() ETModel.Res.AssetInfo:OnStartLoad() (at Assets/Scripts/Core/Res/AssetInfo/AssetInfo.cs:161) ETModel.Res.AssetInfo:StartLoad(Action1) (at Assets/Scripts/Core/Res/AssetInfo/AssetInfo.cs:122) ETModel.Res.AssetManager:LoadAsync(AssetInfo) (at Assets/Scripts/Core/Res/AssetManager.Load.cs:107) ETModel.Res.AssetManager:LoadSync(AssetInfo) (at Assets/Scripts/Core/Res/AssetManager.Load.cs:98) ETModel.Res.AssetManager:StartLoad(AssetInfo) (at Assets/Scripts/Core/Res/AssetManager.Load.cs:152) ETModel.Res.AssetManager:LoadAssetSync(String, LoadType, Action1) (at Assets/Scripts/Core/Res/AssetManager.Load.cs:188) ETModel.APIHelper:GetAsset(String, LoadType, Action1) (at Assets/Scripts/Core/Res/LuaHelper.AAS.cs:32) System.Reflection.MethodBase:Invoke(Object, Object[]) Puerts.OverloadReflectionWrap:Invoke(CallInfo) (at Assets/Libraries/Src/MethodReflection.cs:270) Puerts.MethodReflectionWrap:Invoke(IntPtr, IntPtr, IntPtr, Int32) (at Assets/Libraries/Src/MethodReflection.cs:348) Puerts.JsEnv:InvokeCallback(IntPtr, Int32, IntPtr, IntPtr, Int32) (at Assets/Libraries/Src/JsEnv.cs:236) Puerts.StaticCallbacks:JsEnvCallbackWrap(IntPtr, IntPtr, IntPtr, Int32, Int64) (at Assets/Libraries/Src/StaticCallbacks.cs:21) Puerts.PuertsDLL:InvokeJSFunction(IntPtr, Boolean) Puerts.GenericDelegate:Action(Tab) (at Assets/Libraries/Src/GenericDelegate.cs:459) TabGroup:SetSelected(Tab) (at Assets/Scripts/View/UI/Tab/TabGroup.cs:30) Tab:SetIsOn(Boolean) (at Assets/Scripts/View/UI/Tab/Tab.cs:301) Tab:OnPointerClick(PointerEventData) (at Assets/Scripts/View/UI/Tab/Tab.cs:98) UnityEngine.EventSystems.EventSystem:Update() (at /Applications/Unity/Hub/Editor/2019.4.15f1/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)

zombieyang commented 3 years ago

抱歉有点没看懂

错误是指在打印里面,出现了js_record_content这样的内容,但实际上应该是UIKitchen吗?

以及你的代码里哪里体现出了递归?看不出来是怎么产生这种树形调用的

UpUpLiu commented 3 years ago

递归体现在, Init函数的调用上面. image

UpUpLiu commented 3 years ago

目前我通过另外一种方式绕过这个问题. 我看看能不能搞一个最小复现的demo

UpUpLiu commented 3 years ago

抱歉有点没看懂

错误是指在打印里面,出现了js_record_content这样的内容,但实际上应该是UIKitchen吗?

以及你的代码里哪里体现出了递归?看不出来是怎么产生这种树形调用的

错误的表现是, C#侧传入的参数是 UIKitchen_Install(是一个GameObject) 但是在js侧收到的却是这个函数上一次调用的参数 UIKitchen(也是一个Gameobject)

如果没有出现上面 Init函数的递归调用. 那么此错误可以规避

zombieyang commented 3 years ago

你在QQ群里么,我找你要下demo

UpUpLiu commented 3 years ago

在 498158132

zombieyang commented 3 years ago

https://github.com/Tencent/puerts/commit/fb9f77ef9121f0f1c97a7c75d12c2b7a9fe05270