| 332 | } |
| 333 | |
| 334 | bool ScriptingObject::CreateManaged() |
| 335 | { |
| 336 | #if USE_CSHARP |
| 337 | MObject* managedInstance = CreateManagedInternal(); |
| 338 | if (!managedInstance) |
| 339 | return true; |
| 340 | |
| 341 | // Prevent from object GC destruction |
| 342 | #if USE_NETCORE |
| 343 | auto handle = (MGCHandle)managedInstance; |
| 344 | auto oldHandle = Platform::InterlockedCompareExchange((int64*)&_gcHandle, *(int64*)&handle, 0); |
| 345 | if (*(uint64*)&oldHandle != 0) |
| 346 | #else |
| 347 | auto handle = MCore::GCHandle::New(managedInstance, false); |
| 348 | auto oldHandle = Platform::InterlockedCompareExchange((int32*)&_gcHandle, *(int32*)&handle, 0); |
| 349 | if (*(uint32*)&oldHandle != 0) |
| 350 | #endif |
| 351 | { |
| 352 | // Other thread already created the object before |
| 353 | if (const auto klass = GetClass()) |
| 354 | { |
| 355 | // Reset managed to unmanaged pointer |
| 356 | MCore::ScriptingObject::SetInternalValues(klass, managedInstance, nullptr, nullptr); |
| 357 | } |
| 358 | MCore::GCHandle::Free(handle); |
| 359 | return true; |
| 360 | } |
| 361 | #endif |
| 362 | |
| 363 | // Ensure to be registered |
| 364 | if (!IsRegistered()) |
| 365 | RegisterObject(); |
| 366 | |
| 367 | return false; |
| 368 | } |
| 369 | |
| 370 | #if USE_CSHARP |
| 371 |
no test coverage detected