VST主机 - 泄露的对象 - Juce / C ++

时间:2011-09-13 00:15:11

标签: c++ vst juce

我是一名学习C ++的PHP程序员,因为我构建了一个VST主机。我可能已经咬过的东西比我可以咀嚼的但是我正在取得一些进展(我想)!

我正在使用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技术是什么。

任何能让我朝着正确方向前进的提示都会受到赞赏。

2 个答案:

答案 0 :(得分:4)

有几件事:

  1. 您正在混合使用宽字符串和Microsoft(“T”)字符串。选择一个(适合您的API)。

  2. 不要在C ++中说new。它几乎总是不是你需要的。相反,只需使用自动对象:

  3. File fileHard("C:\\creative\\midi\\m1.mid");
    FileInputStream * fileInputStream = fileHard.createInputStream();
    
    MidiFile midFile;
    midFile.readFrom(*fileInputStream);
    midFile.getNumTracks();
    midFile.getTrack(0);
    

    那应该摆脱大部分内存泄漏。您仍需要以文档中描述的方式释放fileInputStream

答案 1 :(得分:0)

构建VST插件时,一些消息对象泄漏是不可避免的,这是Steinberg接口的问题,而不是您的问题。欲了解更多信息,请访问Juce论坛 http://www.rawmaterialsoftware.com/index.php

相关问题