JUCE icon indicating copy to clipboard operation
JUCE copied to clipboard

[Bug]: AudioTransportSource::hasStreamFinished nullptr exception

Open dobrikov91 opened this issue 1 year ago • 1 comments
trafficstars

Detailed steps on how to reproduce the bug

Juce 7.0.11+

  1. Create empty AudioTransportSource instance
  2. Call hasStreamFinished method

App crashes with nullptr exception


All functions except hasStreamFinished() have nullptr checks, check stacktrace as example

What is the expected behaviour?

hasStreamFinished should return true in case of missing source

Operating systems

Windows

What versions of the operating systems?

Win10

Architectures

64-bit

Stacktrace

bool AudioTransportSource::hasStreamFinished() const noexcept
{
    return positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
              && ! positionableSource->isLooping();
}

void AudioTransportSource::setNextReadPosition (int64 newPosition)
{
    if (positionableSource != nullptr)
    {
        if (sampleRate > 0 && sourceSampleRate > 0)
            newPosition = (int64) ((double) newPosition * sourceSampleRate / sampleRate);

        positionableSource->setNextReadPosition (newPosition);

        if (resamplerSource != nullptr)
            resamplerSource->flushBuffers();
    }
}

int64 AudioTransportSource::getNextReadPosition() const
{
    const ScopedLock sl (callbackLock);

    if (positionableSource != nullptr)
    {
        const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
        return (int64) ((double) positionableSource->getNextReadPosition() * ratio);
    }

    return 0;
}

Plug-in formats (if applicable)

No response

Plug-in host applications (DAWs) (if applicable)

No response

Testing on the develop branch

The bug is present on the develop branch

Code of Conduct

  • [X] I agree to follow the Code of Conduct

dobrikov91 avatar Mar 27 '24 15:03 dobrikov91