From 9538d0dfc81e91ef641f6cf81b65282500f4850d Mon Sep 17 00:00:00 2001 From: hogliux Date: Wed, 2 Sep 2015 21:44:51 +0100 Subject: [PATCH] Fixed a bug where large FFTs would fail --- modules/juce_audio_basics/effects/juce_FFT.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/juce_audio_basics/effects/juce_FFT.cpp b/modules/juce_audio_basics/effects/juce_FFT.cpp index d333c2b62d..2f8829fe8b 100644 --- a/modules/juce_audio_basics/effects/juce_FFT.cpp +++ b/modules/juce_audio_basics/effects/juce_FFT.cpp @@ -230,7 +230,13 @@ void FFT::performRealOnlyForwardTransform (float* d) const noexcept // This can only be called on an FFT object that was created to do forward transforms. jassert (! config->inverse); - Complex* const scratch = static_cast (alloca (16 + sizeof (Complex) * (size_t) size)); + const size_t sizeInBytes = 16 + sizeof (Complex) * (size_t) size; + + Complex* scratch = static_cast (alloca (sizeInBytes)); + + // try malloc if alloca fails + if (scratch == nullptr) + scratch = static_cast (malloc (sizeInBytes)); for (int i = 0; i < size; ++i) { @@ -246,7 +252,13 @@ void FFT::performRealOnlyInverseTransform (float* d) const noexcept // This can only be called on an FFT object that was created to do inverse transforms. jassert (config->inverse); - Complex* const scratch = static_cast (alloca (16 + sizeof (Complex) * (size_t) size)); + const size_t sizeInBytes = 16 + sizeof (Complex) * (size_t) size; + + Complex* scratch = static_cast (alloca (sizeInBytes)); + + // try malloc if alloca fails + if (scratch == nullptr) + scratch = static_cast (malloc (sizeInBytes)); perform (reinterpret_cast (d), scratch);