APE file not destroyed when Fileref set to NULL

Brett Hoyle kickbits at gmail.com
Tue Jul 9 11:29:55 UTC 2013

Thanks for the thoughts Michael,

apeFile is being initially set as NULL when the app opens.

Dynamic_cast is supposed to return null if it "cannot cast a pointer because
it is not a complete object of the required class".
This is where my pseudo-code is a slight lie and doesn't quite tell the
story correctly.

In my actual real life code "if(apeFile = dynamic_cast<TagLib::APE::File *>(
fileRef.file() ))" is never called for the mp3 file prior to
"if(apeFile->APETag()) ".
This is caused by a big chain of else if's where mp3File is tested before
apeFile, mp3File returns true and apeFile is never tested.
So if I am depending on the dynamic_cast to be setting apeFile as NULL, that
is where my code is failing.

I always figured calling
fileRef = TagLib::FileRef();
at the end would NULL everything in the apeFile(or other *Files) also. But
clearly it doesn't and the more I think about the more I shake my head at my
logic :)

My answer is a big bunch of resetting objects back to NULL, this makes it
all work as it should.

		flacFile = NULL;
		mp3File = NULL;
		mp4File = NULL;
		mpcFile = NULL;
		ttaFile = NULL;
		wvFile = NULL;
		oggFile = NULL;
		ogaFile = NULL;
		spxFile = NULL;
		opusFile = NULL;
		wmaFile = NULL;
		aiffFile = NULL;
		wavFile = NULL;
		apeFile = NULL;
		itFile = NULL;
		modFile = NULL;
		s3mFile = NULL;
		xmFile = NULL;

-----Original Message-----
From: taglib-devel-bounces at kde.org [mailto:taglib-devel-bounces at kde.org] On
Behalf Of Michael Pyne
Sent: Tuesday, 9 July 2013 8:37 AM
To: taglib-devel at kde.org
Subject: Re: APE file not destroyed when Fileref set to NULL

On Mon, July 8, 2013 20:17:15 Brett Hoyle wrote:
> Bool  GetInfo(LPTSTR szSource)
> {
> fileRef = TagLib::FileRef(szSource, 1, TagLib::AudioProperties::Fast);
> if( !fileRef.isNull() )
> {
>   if(apeFile = dynamic_cast<TagLib::APE::File *>( fileRef.file() ))
>   {
>     DoStuff();
>   }
> ...
>   if(apeFile)
>   {
>     if(apeFile->APETag())   <<Access violation for files after ape that
> not ape file
>     {
>       DoAPEStuff();
>     }
>   }

> Should I be setting apeFile to NULL myself?

Well, the *pseudo-code* looks to be correct, assuming that dynamic_cast<> is
returning null for objects that are not APE::File*. Is there anywhere else
in the actual code where apeFile is being assigned?

Of course, you can try it anyways and reset all static members when you go
into your function and see if that fixes it. If so there's probably
something else going on within the rest of the code.

 - Michael Pyne

More information about the taglib-devel mailing list