2D Toolkit Forum

2D Toolkit => Support => Topic started by: Jonathans on September 15, 2017, 03:20:31 pm

Title: Game crash when unloading textures with Resources.UnloadUnusedAssets
Post by: Jonathans on September 15, 2017, 03:20:31 pm
I'm currently working with Unity 5.5.0p1 and 2DToolkit 2.4.0. My problem is when i'm switching between scenes, the game crashes approximately 10% of the time. The crash is caused by a call to Resources.UnloadUnusedAssets().

I'm using a lot of SpriteCollections and SpriteAnimator in the game. And i don't know is it's important, but the crash occurs on the PS4 platform.

I narrow down every possible cause to this, so i'm pretty sure the problem is during loading/unloading textures with tk2d.

Maybe you already faced this issue?


Here's a code sample of the function called between scenes:

IEnumerator DeferredUnload()
    {
        //Clear static caches
        AudioManager.ClearAudioCaches();
        PeriodicDamageOnCollision.ClearDamageMemory();
        GameUtil.CurrencyManager.RefreshCurrencyCache();

        yield return new WaitForSeconds(0.1f);

        AsyncOperation unload = Resources.UnloadUnusedAssets();
        while (!unload.isDone) // wait to unload unused assets before GC
        {
            yield return null;
        }

        System.GC.Collect(System.GC.MaxGeneration, System.GCCollectionMode.Forced);

        yield return new WaitForSeconds(0.5f);

        _loadEmptyScene = false;
        _forceLoadingOperation = null;
        _GC_CoroutineStarted = false;
        TransitionCompleteIn(null);

        _isLevelReady = false;
    }

And the call stack from the PS4 Platform:

Il2CppUserAssemblies.prx!<no symbols>+0x88143
Il2CppUserAssemblies.prx!<no symbols>+0x88784
eboot.bin!UnloadUnusedAssetsOperation::IntegrateMainThread()+0x15cc
eboot.bin!PreloadManager::UpdatePreloadingSingleStep(PreloadManager::UpdatePreloadingFlags, int)+0x245
eboot.bin!PreloadManager::UpdatePreloading()+0x17a
eboot.bin!UNITY_main(void*)+0x4378
eboot.bin!main+0x25a5
eboot.bin!_start+0x3f
Title: Re: Game crash when unloading textures with Resources.UnloadUnusedAssets
Post by: unikronsoftware on September 17, 2017, 09:31:43 am
I've not seen this issue before.
Have you raised this with Unity support? Please do that - this sounds like Unity crashing on the platform. Tk2d doesn't do anything particularly odd there, so I don't know how it could cause a crash there.
Title: Re: Game crash when unloading textures with Resources.UnloadUnusedAssets
Post by: Gerdarkes on October 02, 2017, 07:38:09 am
I've had a similar crash happen. It was Unity related.