我是一名 PHP 程序员,在构建 VST 主机时学习 C++。我可能咬得比我能咀嚼的多,但我正在取得一些进展(我认为)!
我在 Visual Studio 2010 中使用 Steinberg VST SDK 和 JUCE 库。我遇到了泄漏的对象错误,我不太了解在搜索收到的错误时找到的解决方案。
这是“输出”选项卡中的错误。我的程序吐出 JUCE Assetion 错误:
*** Leaked objects detected: 44 instance(s) of class MidiEventHolder
score.exe has triggered a breakpoint
我被带到 juce_amalgamated.h 文件中的这条消息:
~LeakCounter()
{
if (numObjects.value > 0)
{
DBG ("*** Leaked objects detected: " << numObjects.value << " instance(s) of class " << getLeakedObjectClassName());
/** If you hit this, then you've leaked one or more objects of the type specified by
the 'OwnerClass' template parameter - the name should have been printed by the line above.
If you're leaking, it's probably because you're using old-fashioned, non-RAII techniques for
your object management. Tut, tut. Always, always use ScopedPointers, OwnedArrays,
ReferenceCountedObjects, etc, and avoid the 'delete' operator at all costs!
*/
jassertfalse;
}
}
这是我认为错误所指的代码:
const wchar_t* midiPath = L"C:\\creative\\midi\\m1.mid";
File* fileHard;
FileInputStream* fileInputStream;
fileHard = new File (T("C:\\creative\\midi\\m1.mid"));
fileInputStream = fileHard->createInputStream();
MidiFile * midFile;
midFile = new MidiFile();
midFile->readFrom(*fileInputStream);
midFile->getNumTracks();
midFile->getTrack(0);
也许我正在接近这种语法更像是 PHP?我不太明白什么是 RAII 技术。
任何让我朝着正确方向前进的提示都值得赞赏。