FMod内存流问题
编辑:嗯...这非常有趣。我将设置设置为指针并传递它。干得漂亮。所以,这个问题就解决了。我会将其开放给任何对答案感兴趣的人。
我在从内存流创建 FMod 声音时遇到问题。我查看了 FMod 附带的 loadfrommemory 示例并遵循了该示例。首先,我正在使用的代码...
CSFX::CSFX(CFileData *fileData)
{
FMOD_RESULT result;
FMOD_CREATESOUNDEXINFO settings;
settings.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
settings.length = fileData->getSize();
_Sound = 0;
std::string temp = "";
for (int i = 0; i < fileData->getSize(); i++)
temp += fileData->getData()[i];
result = tempSys->createSound(temp.c_str(), FMOD_SOFTWARE | FMOD_OPENMEMORY, &settings, &_Sound);
}
就像这样,我在 tempSys->createSound() 上遇到访问冲突。我已经确认 tempSys 是有效的,因为它在从文件创建声音时有效。我还通过将内容写入文件来确认数据中的 char * 是有效的,然后我可以在媒体播放器中打开该文件。我感觉设置有问题。如果我将该参数更改为 0,程序不会崩溃,并且最终结果 = FMOD_ERR_INVALID_HANDLE (考虑到第三个参数为 0,这是有意义的)。知道我做错了什么吗?
另外,请忽略 std::string 的使用,我将它用于某些测试目的。
EDIT: Well...that's very interesting. I made settings into a pointer and passed that. Worked beautifully. So, this is solved. I'll leave it open for anyone curious to the answer.
I'm having an issue creating a sound in FMod from a memory stream. I looked at the loadfrommemory example shipped with FMod and followed that. First, the code I'm using...
CSFX::CSFX(CFileData *fileData)
{
FMOD_RESULT result;
FMOD_CREATESOUNDEXINFO settings;
settings.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
settings.length = fileData->getSize();
_Sound = 0;
std::string temp = "";
for (int i = 0; i < fileData->getSize(); i++)
temp += fileData->getData()[i];
result = tempSys->createSound(temp.c_str(), FMOD_SOFTWARE | FMOD_OPENMEMORY, &settings, &_Sound);
}
As it is like this, I get an access violation on tempSys->createSound(). I've confirmed that tempSys is valid as it works when creating sounds from a file. I've also confirmed the char * with my data is valid by writing the contents to a file, which I was then able to open in Media Player. I have a feeling there's a problem with settings. If I change that parameter to 0, the program doesn't blow up and I end up with result = FMOD_ERR_INVALID_HANDLE (which makes sense considering the 3rd parameter is 0). Any idea what I'm doing wrong?
Also, please disregard the use of std::string, I was using it for some testing purposes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过将设置变成指针来解决。参见下面的代码:
Solved by turning settings into a pointer. See code below:
使用前需要memset设置。
memset(&settings, 0, sizeof(FMOD_CREATESOUNDEXINFO);
否则它将包含垃圾并可能崩溃。
You need to memset settings before using it.
memset(&settings, 0, sizeof(FMOD_CREATESOUNDEXINFO);
Otherwise it will contain garbage and potentially crash.