gtreshchev / AudioAnalysisTools

Audio Analysis Tools plugin for Unreal Engine. Provides a variety of functions for analyzing audio data. Works in conjunction with the Runtime Audio Importer plugin.
MIT License
92 stars 16 forks source link

Exception if you exit whilst AudioAnalysisTools calculation in progress #6

Closed Caffiendish closed 1 year ago

Caffiendish commented 2 years ago

This isn't normally an issue, but I'm throwing all the data at the frame process at the moment.

If you exit whilst the processing is in progress, you get this exception:

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000025b4b06e908

UnrealEditor_AudioAnalysisTools!CalculateButterfly_Generic() [\Plugins\AudioAnalysisTools\Source\AudioAnalysisTools\Private\Analyzers\FFTAnalyzer.cpp:247] UnrealEditor_AudioAnalysisTools!DoWork() [\Plugins\AudioAnalysisTools\Source\AudioAnalysisTools\Private\Analyzers\FFTAnalyzer.cpp:316] UnrealEditor_AudioAnalysisTools!DoWork() [\Plugins\AudioAnalysisTools\Source\AudioAnalysisTools\Private\Analyzers\FFTAnalyzer.cpp:291] UnrealEditor_AudioAnalysisTools!DoWork() [\Plugins\AudioAnalysisTools\Source\AudioAnalysisTools\Private\Analyzers\FFTAnalyzer.cpp:291] UnrealEditor_AudioAnalysisTools!DoWork() [\Plugins\AudioAnalysisTools\Source\AudioAnalysisTools\Private\Analyzers\FFTAnalyzer.cpp:291] UnrealEditor_AudioAnalysisTools!DoWork() [\Plugins\AudioAnalysisTools\Source\AudioAnalysisTools\Private\Analyzers\FFTAnalyzer.cpp:291] UnrealEditor_AudioAnalysisTools!DoWork() [\Plugins\AudioAnalysisTools\Source\AudioAnalysisTools\Private\Analyzers\FFTAnalyzer.cpp:291] UnrealEditor_AudioAnalysisTools!DoWork() [\Plugins\AudioAnalysisTools\Source\AudioAnalysisTools\Private\Analyzers\FFTAnalyzer.cpp:291] UnrealEditor_AudioAnalysisTools!DoWork() [\Plugins\AudioAnalysisTools\Source\AudioAnalysisTools\Private\Analyzers\FFTAnalyzer.cpp:291] UnrealEditor_AudioAnalysisTools!::operator()() [\Plugins\AudioAnalysisTools\Source\AudioAnalysisTools\Private\Analyzers\FFTAnalyzer.cpp:272] UnrealEditor_AudioAnalysisTools!ParallelForImpl::NewParallelForInternal<TFunctionRef<void __cdecl(int)>,<lambda_06f0d5d1c5fc9bccb0e7d1fd1e70ca42>,std::nullptr_t>'::2'::FParallelExecutor::operator()() [C:\Program Files\Epic Games\UE_5.0\Engine\Source\Runtime\Core\Public\Async\ParallelFor.h:566] UnrealEditor_AudioAnalysisTools!LowLevelTasks::TTaskDelegate<void __cdecl(bool),48>::TTaskDelegateImpl<,0>::CallAndMove() [C:\Program Files\Epic Games\UE_5.0\Engine\Source\Runtime\Core\Public\Async\Fundamental\TaskDelegate.h:171] UnrealEditor_Core UnrealEditor_Core UnrealEditor_Core UnrealEditor_Core UnrealEditor_Core UnrealEditor_Core UnrealEditor_Core kernel32

The fix is to check whether the engine is still running, I had the same issue with a plugin I made, I tried a number of things, checking to see if GEngine was valid, whether I could get a valid world pointer, the only thing that reliably worked was a bool, that would be checked before taking action, and set when the destructor was called, for example. I had to use this for the editor preview, otherwise it skipped my destructor:

if WITH_EDITOR

void OnPreEndPIE(const bool bWasSimulatingInEditor) { // Do your thing here }

endif

If you have/find a better solution, I'd love to know, my bool workaround feels very "hacky"!

gtreshchev commented 2 years ago

Can you explain a little more? Are you calling "GetAudioFrameFromSoundWave" (or a similar function) on the entire sound wave buffer and trying to shut down the editor at the same time, causing a crash?

Caffiendish commented 2 years ago

I poured in the entire file as a single frame for ProcessFrame, then closed the preview.

Normally, you probably shouldn't be able to get that sort of event, but it is possible that the ImportedSoundWave might be destroyed (user closes window, a different level is loaded, actor is destroyed, etc) whilst analysis is happening, and before the playback is completed.

gtreshchev commented 2 years ago

The audio buffer should be valid, as AudioAnalysisTools pre-copies it from the sound wave to avoid this error.

Perhaps the crash is due to the FFT buffers that are not valid at that time, as they could have been cleared. Check the latest commit, it might fix your issue.