Skip to content

Commit

Permalink
[unity]解决xil2cpp下,值类型无参构造字段为随机值的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Nov 23, 2023
1 parent 5d35e50 commit 28b0285
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ static void* ObjectAllocate(Il2CppClass *klass)
{
if (Class::IsValuetype(klass))
{
return (void*)(new uint8_t[klass->native_size > 0 ? klass->native_size : (klass->instance_size - sizeof(Il2CppObject))]);
auto size = klass->native_size > 0 ? klass->native_size : (klass->instance_size - sizeof(Il2CppObject));
auto buff = (void*)(new uint8_t[size]);
memset(buff, 0, size);
return buff;
} else {
auto obj = il2cpp::vm::Object::New(klass);
return obj;
Expand Down

0 comments on commit 28b0285

Please sign in to comment.