开发者

FMod Memory Stream Problem

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.


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;
}


You need to memset settings before using it.

memset(&settings, 0, sizeof(FMOD_CREATESOUNDEXINFO);

Otherwise it will contain garbage and potentially crash.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜