Problem deleting AudioThumbnail


#1

Hi,

It’s probably my mistake but I’ve been experiencing problems using AudioThumbnail

I have a class which contains a AudioThumbnail*

I Initalise it in the constructor like this :

[code]_audioThumbnail= new juce::AudioThumbnail(512 ,formatManager ,thumbsCache);

_audioThumbnail->setSource(new juce::FileInputSource(filename));[/code]

filename is of type juce::File and also belongs to the class.

I delete the AudioThumbnail in the destructor

It’s not RAII (yet) and ugly, but I think it should work anyway. However, at destruction, I have an access violation at :CriticalSection::enter()

Here is the stack trace :

[quote]Fusion.exe!juce::CriticalSection::enter() Ligne 71 + 0xc octets C++
Fusion.exe!juce::GenericScopedLockjuce::CriticalSection::GenericScopedLockjuce::CriticalSection(const juce::CriticalSection & lock) Ligne 69 + 0x1e octets C++
Fusion.exe!juce::TimeSliceThread::removeTimeSliceClient(juce::TimeSliceClient * const client) Ligne 52 + 0xf octets C++
Fusion.exe!juce::AudioThumbnail::LevelDataSource::~LevelDataSource() Ligne 95 C++
Fusion.exe!juce::AudioThumbnail::LevelDataSource::scalar deleting destructor'() + 0x16 octets C++ Fusion.exe!juce::ScopedPointer<juce::AudioThumbnail::LevelDataSource>::operator=(juce::AudioThumbnail::LevelDataSource * const newObjectToTakePossessionOf) Ligne 134 + 0x22 octets C++ Fusion.exe!juce::AudioThumbnail::clear() Ligne 546 C++ Fusion.exe!juce::AudioThumbnail::~AudioThumbnail() Ligne 541 C++ Fusion.exe!juce::AudioThumbnail::scalar deleting destructor’() + 0x16 octets C++
Fusion.exe!juce::deleteAndZero<juce::AudioThumbnail *>(juce::AudioThumbnail * & pointer) Ligne 63 + 0x40 octets C++[/quote]

Any hints ?


#2

You’re probably deleting a dangling pointer - use RAII.

And I’d really appreciate it if you didn’t create topics with names that make it sound like there’s a bug in the library! When people are casually looking at the list of topics, it creates a bad (and false) impression that this class has a problem!


#3

Sorry about the title. Hope it’s better now. I switched to “manual memory control” because RAII gave me the exact same symptoms though


#4

Thanks. It looks like a classic dangling pointer deletion to me though. Probably your parent object that’s being deleted incorrectly. Seriously, if you use RAII everywhere, you’ll almost never hit this kind of problem!