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

开启多层FDanglingCheck::FGuard后,最内层的FGuard销毁会销毁所有的CapturedContainers和CapturedStructs(invalid TArray) #727

Open
lzj10 opened this issue Oct 15, 2024 · 0 comments

Comments

@lzj10
Copy link

lzj10 commented Oct 15, 2024

开启多层FDanglingCheck::FGuard后,最内层的FGuard析构会销毁所有的CapturedContainers和CapturedStructs,导致外层的局部变量失效。
出现场景,委托回调到lua,在lua中创建umg,之后局部变量失效
复现方式
1、创建UTestClass,UTestClass2

#pragma once

#include "CoreMinimal.h"
#include "UObject/Object.h"
#include "TestClass1.generated.h"

/**
 * 
 */
UCLASS()
class GANGSTAR_API UTestClass1 : public UObject
{
	GENERATED_BODY()

public:

	UPROPERTY(BlueprintReadWrite)
	TArray<FString> TestArr;
};

#pragma once

#include "CoreMinimal.h"
#include "UnLuaInterface.h"
#include "UObject/Object.h"
#include "TestClass2.generated.h"

UCLASS(Blueprintable)
class GANGSTAR_API UTestClass2 : public UObject,public IUnLuaInterface
{
	GENERATED_BODY()

public:

	UFUNCTION(BlueprintCallable)
	void TestFun()
	{
		TestImpl();
	}

	UFUNCTION(BlueprintCallable)
	void TestFun2()
	{
		TestImp2();
	}

	UFUNCTION(BlueprintImplementableEvent)
	void TestImpl();

	UFUNCTION(BlueprintImplementableEvent)
	void TestImp2();

	virtual FString GetModuleName_Implementation() const override
	{
		return TEXT("Test2Impl");
	};
};

2、lua文件Test2Impl.lua

local Test2Impl = UnLua.Class()

---由于是重写函数,c++从FFunctionDesc::CallLuaInternal调用过来,有一层FGuard
function Test2Impl:TestImpl()
    local testObj = NewObject(UE.UTestClass1, GameInstance)
    local testRef = UnLua.Ref(testObj)
    local testArr = testObj.TestArr

    --testArr正常,可以打印出长度为0
    UnLua.Log("###########   Test arrptr callTest 1: " .. testArr:Length())

    --触发函数调用,由于TestFun2函数在c++中调用了TestImp2,触发了FFunctionDesc::CallLuaInternal
    --开启了新的FGuard,执行结束后FGuard析构testArr 被销毁
    self:TestFun2()

    --testArr报错失效
    UnLua.Log("###########   Test arrptr callTest 2 : " .. testArr:Length())
end

function Test2Impl:TestImp2()
    UnLua.Log("###########   TTest2Impl:TestImp2()")
end

return Test2Impl

3、在lua中创建UTestClass2 并调用TestFun,报错 局部变量testArr被销毁

local obj = NewObject(UE.UTestClass2, GameInstance)
obj:TestFun()

image

@lzj10 lzj10 changed the title 开启多层FDanglingCheck::FGuard后,最内层的FGuard销毁会销毁所有的CapturedContainers和CapturedStructs 开启多层FDanglingCheck::FGuard后,最内层的FGuard销毁会销毁所有的CapturedContainers和CapturedStructs(invalid TArray) Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant