Thank you for your help Chris and StApostol.
Fixed that memset too ;)
I will try to run valgrind, If I find anything useful I will send
another mail, for now there are more snippets from my code.
*** This is the declaration in my class, where OPENAL_MUSIC_BUFFERS is 2:
private:
ALuint iBuffers[OPENAL_MUSIC_BUFFERS];
ALuint iSource;
*** This is my Load method definition (just the part that deals with
openal and ogg):
void Music::Load(const char *filename, ResourceManager *res, IMemoryPool *pool)
{
ASSERT_NULL(filename);
ASSERT_NULL(pool);
ASSERT_NULL(res);
/* ... cut ... */
/* prepare openal */
ALenum err = AL_NO_ERROR;
alGenSources(1, &iSource);
err = alGetError();
if (err != AL_NO_ERROR)
{
Log(TAG "Could not create OpenAL music source
(0x%04x).", alGetError());
return;
}
alGenBuffers(OPENAL_MUSIC_BUFFERS, iBuffers); // create OpenAL buffers
err = alGetError();
if (err != AL_NO_ERROR)
{
alDeleteSources(1, &iSource);
memset(iBuffers, '\0', sizeof(iBuffers));
Log(TAG "Could not generate OpenAL music buffers
(0x%04x).", alGetError());
}
if (ov_fopen(const_cast<char *>(filename), &oggStream) < 0)
{
alDeleteSources(1, &iSource);
alDeleteBuffers(OPENAL_MUSIC_BUFFERS, iBuffers);
memset(iBuffers, '\0', sizeof(iBuffers));
Log(TAG "Could not open '%s' ogg stream (file does not
exist or is not a valid ogg file).", filename);
return;
}
vorbisInfo = ov_info(&oggStream, -1);
vorbisComment = ov_comment(&oggStream, -1);
if (vorbisInfo->channels > 1)
eFormat = AL_FORMAT_STEREO16;
alSource3f(iSource, AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(iSource, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSource3f(iSource, AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSourcef(iSource, AL_ROLLOFF_FACTOR, 0.0);
alSourcei(iSource, AL_SOURCE_RELATIVE, AL_TRUE);
this->Reset();
this->bLoaded = TRUE;
}
*** The Reset method will prepare/initialize the ogg streaming:
void Music::Reset()
{
int queued = 0;
alGetSourcei(iSource, AL_BUFFERS_QUEUED, &queued);
while (queued--)
{
ALuint buffer;
alSourceUnqueueBuffers(iSource, 1, &buffer);
}
ov_raw_seek(&oggStream, 0);
for (u32 i = 0; i < OPENAL_MUSIC_BUFFERS; i++)
ogg_update_stream(&oggStream, vorbisInfo->rate,
eFormat, iBuffers[i], this->bLoop);
alSourceQueueBuffers(iSource, OPENAL_MUSIC_BUFFERS, iBuffers);
}
*** And this is the ogg_update_stream function:
bool ogg_update_stream(OggVorbis_File *oggStream, ogg_int64_t rate,
ALenum format, ALuint buffer, bool loop)
{
char pcm[VORBIS_BUFFER_SIZE];
int size = 0;
int section;
int result;
while (size < VORBIS_BUFFER_SIZE)
{
result = ov_read(oggStream, pcm + size,
VORBIS_BUFFER_SIZE - size, 0, 2, 1, §ion);
if (result > 0)
size += result;
else
if (result < 0)
return false;
else // end of file
{
if (loop)
ov_raw_seek(oggStream, 0);
else
break;
}
}
if (size == 0)
{
ov_raw_seek(oggStream, 0);
return false;
}
alBufferData(buffer, format, pcm, size, rate); // feed data to OpenAL
return true;
}
*** This is my Update streaming method:
BOOL Music::Update()
{
BOOL active = true;
ALint processed = 0;
alGetSourcei(iSource, AL_BUFFERS_PROCESSED, &processed);
while (processed--)
{
ALuint buffer;
alSourceUnqueueBuffers(iSource, 1, &buffer);
active = ogg_update_stream(&oggStream,
vorbisInfo->rate, eFormat, buffer, this->bLoop);
if (active || bLoop)
alSourceQueueBuffers(iSource, 1, &buffer);
}
if (!active)
eState = MusicStopped;
return active;
}
On Sun, Jul 5, 2009 at 7:34 AM, StApostol<
stapostol@...> wrote:
> On Sun, Jul 5, 2009 at 7:41 AM, Chris Robinson <
chris.kcat@...> wrote:
>>
>> On Saturday 04 July 2009 7:37:38 pm fungos wrote:
>> > I'm streaming an ogg music to the openal and if I do an unload and
>> > load another music it works, but when I call the same unload method
>> > from window close event (before any openal deinit) it crashes inside
>> > openal alDeleteBuffers when trying to "free" the second buffer data
>> > (and I don't found if it is really related to closing window it is
>> > just the way I can reproduce).
>>
> I have seen this happen when the buffers aren't allocated through
> alGenBuffers. I don't know if this is allowed by the specs but Creative's
> drivers seem to ignore this silently, while OpenAL Soft is more strict.
>
>
> _______________________________________________
> Openal mailing list
>
Openal@...
>
http://opensource.creative.com/mailman/listinfo/openal>
>
--
Animal Liberation Front
http://www.animal-liberation.com/_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal