Guard empty OpenAL buffer data slices
This commit is contained in:
committed by
Brandon McGinty
parent
0e537a144d
commit
c96617c71d
@@ -57,6 +57,9 @@ func (self Buffer) set3f(param int32, value1, value2, value3 float32) {
|
||||
|
||||
// Renamed, was Bufferfv.
|
||||
func (self Buffer) setfv(param int32, values []float32) {
|
||||
if len(values) == 0 {
|
||||
return
|
||||
}
|
||||
C.walBufferfv(C.ALuint(self), C.ALenum(param), unsafe.Pointer(&values[0]))
|
||||
}
|
||||
|
||||
@@ -72,6 +75,9 @@ func (self Buffer) set3i(param int32, value1, value2, value3 int32) {
|
||||
|
||||
// Renamed, was Bufferiv.
|
||||
func (self Buffer) setiv(param int32, values []int32) {
|
||||
if len(values) == 0 {
|
||||
return
|
||||
}
|
||||
C.walBufferiv(C.ALuint(self), C.ALenum(param), unsafe.Pointer(&values[0]))
|
||||
}
|
||||
|
||||
@@ -91,6 +97,9 @@ func (self Buffer) get3f(param int32) (value1, value2, value3 float32) {
|
||||
|
||||
// Renamed, was GetBufferfv.
|
||||
func (self Buffer) getfv(param int32, values []float32) {
|
||||
if len(values) == 0 {
|
||||
return
|
||||
}
|
||||
C.walGetBufferfv(C.ALuint(self), C.ALenum(param), unsafe.Pointer(&values[0]))
|
||||
return
|
||||
}
|
||||
@@ -111,6 +120,9 @@ func (self Buffer) get3i(param int32) (value1, value2, value3 int32) {
|
||||
|
||||
// Renamed, was GetBufferiv.
|
||||
func (self Buffer) getiv(param int32, values []int32) {
|
||||
if len(values) == 0 {
|
||||
return
|
||||
}
|
||||
C.walGetBufferiv(C.ALuint(self), C.ALenum(param), unsafe.Pointer(&values[0]))
|
||||
}
|
||||
|
||||
@@ -146,31 +158,49 @@ const (
|
||||
// in Hz.
|
||||
// Renamed, was BufferData.
|
||||
func (self Buffer) SetData(format Format, data []byte, frequency int32) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
C.alBufferData(C.ALuint(self), C.ALenum(format), unsafe.Pointer(&data[0]),
|
||||
C.ALsizei(len(data)), C.ALsizei(frequency))
|
||||
}
|
||||
|
||||
func (self Buffer) SetDataInt16(format Format, data []int16, frequency int32) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
C.alBufferData(C.ALuint(self), C.ALenum(format), unsafe.Pointer(&data[0]),
|
||||
C.ALsizei(len(data)*2), C.ALsizei(frequency))
|
||||
}
|
||||
|
||||
func (self Buffer) SetDataMono8(data []byte, frequency int32) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
C.alBufferData(C.ALuint(self), C.ALenum(FormatMono8), unsafe.Pointer(&data[0]),
|
||||
C.ALsizei(len(data)), C.ALsizei(frequency))
|
||||
}
|
||||
|
||||
func (self Buffer) SetDataMono16(data []int16, frequency int32) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
C.alBufferData(C.ALuint(self), C.ALenum(FormatMono16), unsafe.Pointer(&data[0]),
|
||||
C.ALsizei(len(data)*2), C.ALsizei(frequency))
|
||||
}
|
||||
|
||||
func (self Buffer) SetDataStereo8(data [][2]byte, frequency int32) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
C.alBufferData(C.ALuint(self), C.ALenum(FormatStereo8), unsafe.Pointer(&data[0]),
|
||||
C.ALsizei(len(data)*2), C.ALsizei(frequency))
|
||||
}
|
||||
|
||||
func (self Buffer) SetDataStereo16(data [][2]int16, frequency int32) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
C.alBufferData(C.ALuint(self), C.ALenum(FormatStereo16), unsafe.Pointer(&data[0]),
|
||||
C.ALsizei(len(data)*4), C.ALsizei(frequency))
|
||||
}
|
||||
|
||||
@@ -45,6 +45,13 @@ func TestEmptySliceAPIsDoNotPanic(t *testing.T) {
|
||||
source.Getiv(0, nil)
|
||||
source.QueueBuffers(nil)
|
||||
source.UnqueueBuffers(nil)
|
||||
var buffer openal.Buffer
|
||||
buffer.SetData(openal.FormatMono8, nil, 0)
|
||||
buffer.SetDataInt16(openal.FormatMono16, nil, 0)
|
||||
buffer.SetDataMono8(nil, 0)
|
||||
buffer.SetDataMono16(nil, 0)
|
||||
buffer.SetDataStereo8(nil, 0)
|
||||
buffer.SetDataStereo16(nil, 0)
|
||||
if got := openal.NewSources(0); len(got) != 0 {
|
||||
t.Fatalf("got %d sources", len(got))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user