void USoundWave::FreeResources() { check(IsInAudioThread()); // Housekeeping of stats DEC_FLOAT_STAT_BY( STAT_AudioBufferTime, Duration ); DEC_FLOAT_STAT_BY( STAT_AudioBufferTimeChannels, NumChannels * Duration ); // GEngine is NULL during script compilation and GEngine->Client and its audio device might be // destroyed first during the exit purge. if( GEngine && !GExitPurge ) { // Notify the audio device to free the bulk data associated with this wave. FAudioDeviceManager* AudioDeviceManager = GEngine->GetAudioDeviceManager(); if (AudioDeviceManager) { AudioDeviceManager->StopSoundsUsingResource(this); AudioDeviceManager->FreeResource(this); } } if (CachedRealtimeFirstBuffer) { FMemory::Free(CachedRealtimeFirstBuffer); CachedRealtimeFirstBuffer = nullptr; } // Just in case the data was created but never uploaded if (RawPCMData) { FMemory::Free(RawPCMData); RawPCMData = nullptr; } // Remove the compressed copy of the data RemoveAudioResource(); // Stat housekeeping DEC_DWORD_STAT_BY(STAT_AudioMemorySize, TrackedMemoryUsage); DEC_DWORD_STAT_BY(STAT_AudioMemory, TrackedMemoryUsage); TrackedMemoryUsage = 0; ResourceID = 0; bDynamicResource = false; DecompressionType = DTYPE_Setup; bDecompressedFromOgg = 0; USoundWave* SoundWave = this; FAudioThread::RunCommandOnGameThread([SoundWave]() { SoundWave->ResourceState = ESoundWaveResourceState::Freed; }, TStatId()); }
void USoundWave::FreeResources() { // Housekeeping of stats DEC_FLOAT_STAT_BY( STAT_AudioBufferTime, Duration ); DEC_FLOAT_STAT_BY( STAT_AudioBufferTimeChannels, NumChannels * Duration ); // GEngine is NULL during script compilation and GEngine->Client and its audio device might be // destroyed first during the exit purge. if( GEngine && !GExitPurge ) { // Notify the audio device to free the bulk data associated with this wave. FAudioDevice* AudioDevice = GEngine->GetAudioDevice(); if (AudioDevice != NULL) { TArray<UAudioComponent*> StoppedComponents; AudioDevice->StopSoundsUsingResource(this, StoppedComponents); AudioDevice->FreeResource( this ); } } // Just in case the data was created but never uploaded if (RawPCMData != NULL) { FMemory::Free(RawPCMData); RawPCMData = NULL; } // Remove the compressed copy of the data RemoveAudioResource(); // Stat housekeeping DEC_DWORD_STAT_BY(STAT_AudioMemorySize, TrackedMemoryUsage); DEC_DWORD_STAT_BY(STAT_AudioMemory, TrackedMemoryUsage); TrackedMemoryUsage = 0; SampleRate = 0; Duration = 0.0f; ResourceID = 0; bDynamicResource = false; DecompressionType = DTYPE_Setup; bDecompressedFromOgg = 0; RawPCMDataSize = 0; }