[Openal] Buffer size problem
Chris Robinson
chris.kcat at gmail.com
Fri Jul 3 19:53:24 PDT 2009
On Friday 03 July 2009 11:40:51 am Jimmy Gervais wrote:
> ALvoid * PTampon1; // My Buffer
> short * Tampon1;
> Tampon1 = (short*)PTampon1;
> Tampon1 = new short [taille];
...
> std::cout << "Buffers ... " << std::endl;
> alBufferData(MesTampons[0], AL_FORMAT_STEREO16, PTampon1, taille,
> 44100); // Hangs here when size > ~ 250'000
This doesn't look right. PTampon1 is left uninitialized, Tampon1 is set to the
uninitialized value, then overwritten with a new buffer. PTampon1, still
uninitialized, is passed to alBufferData. That it sometimes works is just a
coincidence: if PTampon1 happens to be NULL, alBufferData will cause an error
and return without crashing (though attaching it to a source an d trying to
play the source will fail, too). If it's a non-NULL value, it will likely
crash.
Something like this should work:
short * Tampon1; // My Buffer
Tampon1 = new short [taille];
...
std::cout << "Buffers ... " << std::endl;
alBufferData(MesTampons[0], AL_FORMAT_STEREO16, Tampon1, taille, 44100);
You don't need the extra PTampon1 pointer. It may also help to turn on
compiler warnings (-Wall -Wextra in GCC), as that would have warned you about
the uninitialized pointer.
More information about the Openal
mailing list