Closed mirchd closed 6 years ago
self.posArr[1] = {FVector2D.New(0.0, -92.0)} self.posArr[2] = {FVector2D.New(-103.0, 21.0), FVector2D.New(103.0, 21.0)} self.posArr[3] = {FVector2D.New(0.0, -92.0), FVector2D.New(-103.0, 21.0), FVector2D.New(103.0, 21.0)} self.posArr[4] = {FVector2D.New(-53.0, -72.0), FVector2D.New(53.0, -72.0), FVector2D.New(-103.0, 21.0), FVector2D.New(103.0, 21.0)} self.posArr[5] = {FVector2D.New(0.0, -100.0), FVector2D.New(-92.0, -52.0), FVector2D.New(92.0, -52.0), FVector2D.New(-103.0, 32.0), FVector2D.New(103.0, 32.0)} self.posArr[6] = {FVector2D.New(-35.0, -92.0), FVector2D.New(35.0, -92.0), FVector2D.New(-98.0, -44.0), FVector2D.New(98.0, -44.0), FVector2D.New(-103.0, 32.0), FVector2D.New(103.0, 32.0)}
dump(self.posArr)
the data of array is not the same as above
FVector2D.New = ULuautils.FVector2D_New
It's an opmization for lua garbagecollection.
When you get c++ struct property, or call a function which return struct.
What you get is a temp ins,The memory will be reused.As you mention,the lenth of the temp buffer was limited to 10.
The original FVector2D.New allocate memory in heap.But can't pass value for construction.
So i have to write
local v = FVector.New()
v.X = 10, v.Y = 20
for convinient, I replace it with ULuautils.FVector2D_New which cause such bug.
for each struct, there is a function named "Copy",It will create a same instance in heap.you can write
self.posArr[2] = {FVector2D.New(-103.0, 21.0):Copy(), FVector2D.New(103.0, 21.0):Copy()}
finally,for performance consideration, you should avoid cross lua and c++ and create gc object.
and you can increase the length of the buffer.
Remenber,don't keep the temp ins for later use.if you want. call Copy() to create the same one managed by lua garbage system.
ok, thank you for quickly reply
UTableUtil::GetTempIns just can keep 10 ins, If lua ref C++ object, and in single functin or single class, it is very easy to over 10, I need to new lua and copy ref C++ object to this new lua to avoid it, can any other way?