| 657 | } |
| 658 | |
| 659 | void Scripting::Release() |
| 660 | { |
| 661 | PROFILE_CPU(); |
| 662 | PROFILE_MEM(Scripting); |
| 663 | // Note: this action can be called from main thread (due to Mono problems with assemblies actions from other threads) |
| 664 | ASSERT(IsInMainThread()); |
| 665 | |
| 666 | // Fire event |
| 667 | ScriptsUnload(); |
| 668 | |
| 669 | // Release managed objects instances for persistent objects (assets etc.) |
| 670 | ReleaseObjects(false); |
| 671 | |
| 672 | auto* flaxEngineModule = (NativeBinaryModule*)GetBinaryModuleFlaxEngine(); |
| 673 | onEngineUnloading(flaxEngineModule->Assembly); |
| 674 | |
| 675 | // Unload assemblies (from back to front) |
| 676 | { |
| 677 | LOG(Info, "Unloading binary modules"); |
| 678 | auto modules = BinaryModule::GetModules(); |
| 679 | for (int32 i = modules.Count() - 1; i >= 0; i--) |
| 680 | { |
| 681 | auto module = modules[i]; |
| 682 | module->Destroy(false); |
| 683 | } |
| 684 | _nonNativeModules.ClearDelete(); |
| 685 | _hasGameModulesLoaded = false; |
| 686 | } |
| 687 | |
| 688 | // Cleanup |
| 689 | MCore::GC::Collect(); |
| 690 | MCore::GC::WaitForPendingFinalizers(); |
| 691 | |
| 692 | // Flush objects |
| 693 | ObjectsRemovalService::Flush(); |
| 694 | |
| 695 | // Switch domain |
| 696 | auto rootDomain = MCore::GetRootDomain(); |
| 697 | if (rootDomain) |
| 698 | { |
| 699 | if (!rootDomain->SetCurrentDomain(false)) |
| 700 | { |
| 701 | LOG(Error, "Failed to set current domain to root"); |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | #if !USE_SCRIPTING_SINGLE_DOMAIN |
| 706 | MCore::UnloadDomain("Scripts Domain"); |
| 707 | #endif |
| 708 | } |
| 709 | |
| 710 | #if USE_EDITOR |
| 711 |
no test coverage detected