| 399 | } |
| 400 | |
| 401 | void BinaryAsset::OnStorageReloaded(FlaxStorage* storage, bool failed) |
| 402 | { |
| 403 | ASSERT(Storage != nullptr && Storage == storage); |
| 404 | |
| 405 | // Clear header (prevent from using old chunks) |
| 406 | auto oldHeader = _header; |
| 407 | Platform::MemoryClear(_header.Chunks, sizeof(_header.Chunks)); |
| 408 | |
| 409 | // Check if reload failed |
| 410 | if (failed) |
| 411 | { |
| 412 | LOG(Error, "Asset storage reloading failed. Asset: \'{0}\'.", ToString()); |
| 413 | return; |
| 414 | } |
| 415 | |
| 416 | // Gather updated asset init data |
| 417 | AssetInitData initData; |
| 418 | if (Storage->LoadAssetHeader(GetID(), initData)) |
| 419 | { |
| 420 | LOG(Error, "Asset header loading failed. Asset: \'{0}\'.", ToString()); |
| 421 | return; |
| 422 | } |
| 423 | if (oldHeader.ID != initData.Header.ID || oldHeader.TypeName != initData.Header.TypeName) |
| 424 | { |
| 425 | LOG(Warning, "Asset reloading data mismatch. Old ID:{0},TypeName:{1}, New ID:{2},TypeName:{3}. Asset: \'{4}\'.", oldHeader.ID, oldHeader.TypeName, initData.Header.ID, initData.Header.TypeName, GetPath()); |
| 426 | |
| 427 | // Unload asset (file contains different asset data) |
| 428 | // For eg. texture has been changed into sprite atlas on reimport |
| 429 | Content::UnloadAsset(this); |
| 430 | |
| 431 | // Delete managed object now because it way fail when we recreate the asset object and want to register the new managed object (IDs will overlap) |
| 432 | DeleteManaged(); |
| 433 | |
| 434 | return; |
| 435 | } |
| 436 | |
| 437 | // Reinitialize (file may modify some data so it needs to be flushed) |
| 438 | if (Init(initData)) |
| 439 | { |
| 440 | LOG(Error, "Asset reloading failed. Asset: \'{0}\'.", ToString()); |
| 441 | } |
| 442 | |
| 443 | // Don't reload on save |
| 444 | if (_isSaving == false) |
| 445 | { |
| 446 | Reload(); |
| 447 | } |
| 448 | |
| 449 | // Inform dependant asset (use cloned version because it might be modified by assets when they got reloaded) |
| 450 | auto dependantAssets = _dependantAssets; |
| 451 | for (auto& e : dependantAssets) |
| 452 | { |
| 453 | e->OnDependencyModified(this); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | void BinaryAsset::OnDeleteObject() |
| 458 | { |
nothing calls this directly
no test coverage detected