- blocked the destructor in the sound font reader base class.

If ZMusic is to act like an external library it may not call delete on external objects because there is no guarantee that they use the same allocator. Deletion must be done as a virtual function to ensure that the correct operator delete gets called, which, unlike the actual destructor is not virtual itself.
This commit is contained in:
Christoph Oelckers 2020-01-01 16:11:39 +01:00
parent 7156611643
commit fe0a6b00ce
4 changed files with 8 additions and 6 deletions

View file

@ -224,8 +224,8 @@ struct VectorReader : public MemoryReader
//========================================================================== //==========================================================================
// //
// The follpwing two functions are needed to allow using UTF-8 in the file interface. // The following two functions are needed to allow using UTF-8 in the file interface.
// fopen on Windows is only safe for ASCII, // fopen on Windows is only safe for ASCII.
// //
//========================================================================== //==========================================================================
@ -271,10 +271,12 @@ inline bool fileExists(const char *fn)
class SoundFontReaderInterface class SoundFontReaderInterface
{ {
public: protected:
virtual ~SoundFontReaderInterface() {} virtual ~SoundFontReaderInterface() {}
public:
virtual struct FileInterface* open_file(const char* fn) = 0; virtual struct FileInterface* open_file(const char* fn) = 0;
virtual void add_search_path(const char* path) = 0; virtual void add_search_path(const char* path) = 0;
virtual void close() { delete this; }
}; };

View file

@ -703,7 +703,7 @@ Instruments::~Instruments()
drumset[i] = NULL; drumset[i] = NULL;
} }
} }
if (sfreader != nullptr) delete sfreader; if (sfreader != nullptr) sfreader->close();
sfreader = nullptr; sfreader = nullptr;
} }

View file

@ -73,7 +73,7 @@ Instruments::~Instruments()
free_tone_bank(); free_tone_bank();
free_instrument_map(); free_instrument_map();
if (sfreader != nullptr) delete sfreader; if (sfreader != nullptr) sfreader->close();
} }
void Instruments::free_instrument(Instrument *ip) void Instruments::free_instrument(Instrument *ip)

View file

@ -1326,7 +1326,7 @@ void Instruments::load_patch(struct _mdi *mdi, unsigned short patchid)
Instruments::~Instruments() Instruments::~Instruments()
{ {
FreePatches(); FreePatches();
delete sfreader; sfreader->close();
} }