FMod内存流问题

发布于 2024-12-06 01:11:26 字数 875 浏览 3 评论 0原文

编辑:嗯...这非常有趣。我将设置设置为指针并传递它。干得漂亮。所以,这个问题就解决了。我会将其开放给任何对答案感兴趣的人。

我在从内存流创建 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我一直都在从未离去 2024-12-13 01:11:26

通过将设置变成指针来解决。参见下面的代码:

CSFX::CSFX(CFileData *fileData)
{
FMOD_RESULT result;
FMOD_CREATESOUNDEXINFO * settings;

_Sound = 0;
std::string temp = "";

for (int i = 0; i < fileData->getSize(); i++)
    temp += fileData->getData()[i];
settings = new FMOD_CREATESOUNDEXINFO();
settings->cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
settings->length = fileData->getSize();

result = tempSys->createSound(temp.c_str(), FMOD_SOFTWARE | FMOD_OPENMEMORY, settings, &_Sound);
delete settings;
settings = 0;
}

Solved by turning settings into a pointer. See code below:

CSFX::CSFX(CFileData *fileData)
{
FMOD_RESULT result;
FMOD_CREATESOUNDEXINFO * settings;

_Sound = 0;
std::string temp = "";

for (int i = 0; i < fileData->getSize(); i++)
    temp += fileData->getData()[i];
settings = new FMOD_CREATESOUNDEXINFO();
settings->cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
settings->length = fileData->getSize();

result = tempSys->createSound(temp.c_str(), FMOD_SOFTWARE | FMOD_OPENMEMORY, settings, &_Sound);
delete settings;
settings = 0;
}
心的位置 2024-12-13 01:11:26

使用前需要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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文