0

全部。终于到了为我的游戏引擎添加音频的时候了。

我有简单的 SoundEffect->Play() 函数工作得很好,但我想要 SoundEffectInstances 以便我可以应用 3D 效果等。

当我调用 SoundEffect->CreateInstance() 时,它返回一个 NULL 指针。我尝试打开音频引擎中的调试层,但它没有给我任何信息。

否则,基本 SoundEffects 可以正常工作。我能够播放声音并且他们加载了他们的文件(非空指针)。

据我所知,我正在按照教程中的说明进行操作。我是否遗漏了什么,或者 CreateInstance() 调用失败的原因是什么?我可以确认在向量中使用指向结构的指针没有问题,因为我可以获取该引用,然后通过引用获取 SoundEffect->Play() 它。

谢谢。

代码片段:

struct SoundEffectWrapper
{
    unique_ptr<SoundEffect> sound;
    string soundName;
};

struct SoundEffectInstanceWrapper
{
    unique_ptr<SoundEffectInstance> sound;
    string soundName;
};

vector<SoundEffectWrapper> Sounds;
vector<SoundEffectInstanceWrapper> SoundInstances;

SoundEffectInstanceWrapper* SoundManagerClass::GetSoundInstance(string soundName)
{
//Returns an instance of a non-3D sound
SoundEffectWrapper* pSEW = GetSoundEffectWrapper(soundName);

if (pSEW != NULL)
{
    //DEBUG trying to create the sound directly from the sound instead of through a pointer 
    //to the vector to remove as many layers of abstraction as possible.
    unique_ptr<SoundEffectInstance> testSound = Sounds[2].sound->CreateInstance(); //still returns NULL pointer


    //VVVVcode is supposed to do this VVVVVVV
    SoundInstances.push_back(SoundEffectInstanceWrapper());

    int ind = SoundInstances.size() - 1;

    SoundInstances[ind].sound = pSEW->sound->CreateInstance(); //Returns NULL pointer
    SoundInstances[ind].soundName = pSEW->soundName;

    return &SoundInstances[ind];
}
else
{
    return NULL;
}

}

2019 年 3 月 5 日更新对于 Chuck:感谢 Chuck 的回复。当我说它返回空值时,我可能说错了。具体来说,参数 mBase{voice=null。我创建了一些代码来排除向量的问题,然后我下载了项目并进入了创建实例函数。根据局部变量选项卡,voice在调用return之前为NULL。这是一个代码片段和一张图片,显示了我在屏幕上看到的内容:

wstring filepath = L"..//Resources/Audio/Player/FootStepWalk.wav";
auto sound = make_unique<SoundEffect>(audioEngine.audEngine.get(), filepath.c_str());

auto soundInstance = sound->CreateInstance();

if (!soundInstance)
{
    //This doesn't occur even though voice is null
    MessageBox(NULL, "Failed to create sound instance", "Derp", MB_OK);
}
//This sound doesn't play, but it doesn't throw an exception either.
soundInstance->Play();

调试器视图

是否有可能无法为声音实例分配源语音?

更新 2:

一切正常但没有声音的图片: 调试

4

0 回答 0