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

ue对应的bindstruct的修复 #1207

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
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
28 changes: 13 additions & 15 deletions unreal/Puerts/Source/JsEnv/Private/CppObjectMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,29 +251,27 @@ void FCppObjectMapper::BindCppObject(
DataTransfer::SetPointer(Isolate, JSObject, Ptr, 0);
DataTransfer::SetPointer(Isolate, JSObject, ClassDefinition->TypeId, 1);

if (!PassByPointer)
auto Iter = CDataCache.find(Ptr);
FObjectCacheNode* CacheNodePtr;
if (Iter != CDataCache.end())
{
CacheNodePtr = Iter->second.Add(ClassDefinition->TypeId);
}
else
{
auto Ret = CDataCache.insert({Ptr, FObjectCacheNode(ClassDefinition->TypeId)});
auto CacheNodePtr = &Ret.first->second;
CacheNodePtr->Value.Reset(Isolate, JSObject);
CacheNodePtr = &Ret.first->second;
}
CacheNodePtr->Value.Reset(Isolate, JSObject);

if (!PassByPointer)
{
CDataFinalizeMap[Ptr] = ClassDefinition->Finalize;
CacheNodePtr->Value.SetWeak<JSClassDefinition>(
ClassDefinition, CDataGarbageCollectedWithFree, v8::WeakCallbackType::kInternalFields);
}
else
{
auto Iter = CDataCache.find(Ptr);
FObjectCacheNode* CacheNodePtr;
if (Iter != CDataCache.end())
{
CacheNodePtr = Iter->second.Add(ClassDefinition->TypeId);
}
else
{
auto Ret = CDataCache.insert({Ptr, FObjectCacheNode(ClassDefinition->TypeId)});
CacheNodePtr = &Ret.first->second;
}
CacheNodePtr->Value.Reset(Isolate, JSObject);
CacheNodePtr->Value.SetWeak<JSClassDefinition>(
ClassDefinition, CDataGarbageCollectedWithoutFree, v8::WeakCallbackType::kInternalFields);
}
Expand Down
10 changes: 9 additions & 1 deletion unreal/Puerts/Source/JsEnv/Private/JsEnvImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2635,7 +2635,15 @@ void FJsEnvImpl::BindStruct(
auto MemoryHolder = v8::ArrayBuffer::New(MainIsolate, std::move(Backing));
__USE(JSObject->Set(MainIsolate->GetCurrentContext(), 0, MemoryHolder));
#else
auto CacheNodePtr = &StructCache.Emplace(Ptr, FObjectCacheNode(ScriptStructWrapper->Struct.Get()));
auto CacheNodePtr = StructCache.Find(Ptr);
if (CacheNodePtr)
{
CacheNodePtr = CacheNodePtr->Add(ScriptStructWrapper->Struct.Get());
}
else
{
CacheNodePtr = &StructCache.Emplace(Ptr, FObjectCacheNode(ScriptStructWrapper->Struct.Get()));
}
CacheNodePtr->Value.Reset(MainIsolate, JSObject);
ScriptStructFinalizeInfoMap.Add(Ptr, {ScriptStructWrapper->Struct, ScriptStructWrapper->ExternalFinalize});
CacheNodePtr->Value.SetWeak<FScriptStructWrapper>(
Expand Down