From c96617c71d7175dc55bb475cf2082006aab11128 Mon Sep 17 00:00:00 2001 From: "Brandon McGinty (chatgpt)" Date: Sun, 9 Aug 2026 18:01:41 -0400 Subject: [PATCH] Guard empty OpenAL buffer data slices --- gumble/go-openal/openal/buffer.go | 30 ++++++++++++++++++++++++++ gumble/go-openal/openal/openal_test.go | 7 ++++++ 2 files changed, 37 insertions(+) diff --git a/gumble/go-openal/openal/buffer.go b/gumble/go-openal/openal/buffer.go index 39ca253..0527564 100644 --- a/gumble/go-openal/openal/buffer.go +++ b/gumble/go-openal/openal/buffer.go @@ -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)) } diff --git a/gumble/go-openal/openal/openal_test.go b/gumble/go-openal/openal/openal_test.go index 14eed51..e2ec9a0 100644 --- a/gumble/go-openal/openal/openal_test.go +++ b/gumble/go-openal/openal/openal_test.go @@ -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)) }