| 271 | } |
| 272 | |
| 273 | void Asset::OnDeleteObject() |
| 274 | { |
| 275 | ASSERT(IsInMainThread()); |
| 276 | |
| 277 | // Send event to the gameplay so it can release handle to this asset |
| 278 | // This may happen when asset gets removed but sth is still referencing it (eg. in managed code) |
| 279 | if (!IsInternalType()) |
| 280 | Content::AssetDisposing(this); |
| 281 | |
| 282 | const bool wasMarkedToDelete = _deleteFileOnUnload != 0; |
| 283 | #if USE_EDITOR |
| 284 | const String path = wasMarkedToDelete ? String(GetPath()) : String::Empty; |
| 285 | #endif |
| 286 | const Guid id = GetID(); |
| 287 | |
| 288 | // Fire unload event (every object referencing this asset or it's data should release reference so later actions are safe) |
| 289 | onUnload_MainThread(); |
| 290 | |
| 291 | // Remove from pool |
| 292 | Content::onAssetUnload(this); |
| 293 | |
| 294 | // Unload asset data (in a safe way to protect asset data) |
| 295 | Locker.Lock(); |
| 296 | if (IsLoaded()) |
| 297 | { |
| 298 | unload(false); |
| 299 | Platform::AtomicStore(&_loadState, (int64)LoadState::Unloaded); |
| 300 | } |
| 301 | Locker.Unlock(); |
| 302 | |
| 303 | #if BUILD_DEBUG |
| 304 | // Ensure no object is referencing it (except managed instance if exists) |
| 305 | //ASSERT(_refCount == (HasManagedInstance() ? 1 : 0)); |
| 306 | #endif |
| 307 | |
| 308 | // Base (after it `this` is invalid) |
| 309 | ManagedScriptingObject::OnDeleteObject(); |
| 310 | |
| 311 | #if USE_EDITOR |
| 312 | if (wasMarkedToDelete) |
| 313 | { |
| 314 | LOG(Info, "Deleting asset '{0}':{1}.", path, id.ToString()); |
| 315 | |
| 316 | // Remove from registry |
| 317 | Content::GetRegistry()->DeleteAsset(id, nullptr); |
| 318 | |
| 319 | // Delete file |
| 320 | if (!IsVirtual()) |
| 321 | Content::deleteFileSafety(path, &id); |
| 322 | } |
| 323 | #endif |
| 324 | } |
| 325 | |
| 326 | bool Asset::CreateManaged() |
| 327 | { |
no test coverage detected