Ejemplo n.º 1
0
/** Clears and optionally backs up all references to renderer module classes in other modules, particularly engine. */
void ClearReferencesToRendererModuleClasses(
    TMap<UWorld*, bool>& WorldsToUpdate,
    TMap<FMaterialShaderMap*, TScopedPointer<TArray<uint8> > >& ShaderMapToSerializedShaderData,
    TScopedPointer<TArray<uint8> >& GlobalShaderData,
    TMap<FShaderType*, FString>& ShaderTypeNames,
    TMap<FVertexFactoryType*, FString>& VertexFactoryTypeNames)
{
    // Destroy all renderer scenes
    for (TObjectIterator<UWorld> WorldIt; WorldIt; ++WorldIt)
    {
        UWorld* World = *WorldIt;

        if (World->Scene)
        {
            WorldsToUpdate.Add(World, World->FXSystem != NULL);

            for (int32 LevelIndex = 0; LevelIndex < World->GetNumLevels(); LevelIndex++)
            {
                ULevel* Level = World->GetLevel(LevelIndex);
                Level->ReleaseRenderingResources();
            }

            if (World->FXSystem != NULL)
            {
                FFXSystemInterface::Destroy(World->FXSystem);
                World->FXSystem = NULL;
            }

            World->Scene->Release();
            World->Scene = NULL;
        }
    }

    // Save off shaders by serializing them into memory, and remove all shader map references to FShaders
    GlobalShaderData = TScopedPointer<TArray<uint8> >(BackupGlobalShaderMap(GRHIShaderPlatform_DEPRECATED));
    UMaterial::BackupMaterialShadersToMemory(ShaderMapToSerializedShaderData);

    // Verify no FShaders still in memory
    for(TLinkedList<FShaderType*>::TIterator It(FShaderType::GetTypeList()); It; It.Next())
    {
        FShaderType* ShaderType = *It;
        check(ShaderType->GetNumShaders() == 0);
        ShaderTypeNames.Add(ShaderType, ShaderType->GetName());
    }

    for(TLinkedList<FVertexFactoryType*>::TIterator It(FVertexFactoryType::GetTypeList()); It; It.Next())
    {
        FVertexFactoryType* VertexFactoryType = *It;
        VertexFactoryTypeNames.Add(VertexFactoryType, VertexFactoryType->GetName());
    }

    // Destroy misc renderer module classes and remove references
    FSceneViewStateReference::DestroyAll();
    FSlateApplication::Get().InvalidateAllViewports();

    // Invalidate cached shader type data
    UninitializeShaderTypes();

    // Delete pending cleanup objects to remove those references, which are potentially renderer module classes
    FPendingCleanupObjects* PendingCleanupObjects = GetPendingCleanupObjects();
    delete PendingCleanupObjects;
    GEngine->EngineLoop->ClearPendingCleanupObjects();

    ResetCachedRendererModule();
}