veandco / go-sdl2

SDL2 binding for Go
https://godoc.org/github.com/veandco/go-sdl2
BSD 3-Clause "New" or "Revised" License
2.17k stars 219 forks source link

Unable to call RenderGeometery with nil indicies #516

Open advisoft opened 2 years ago

advisoft commented 2 years ago

The SDL2 documentation says you can pass in NULL indices.

image

The go-sdl2 function assumes there is at least one indice passed in:

image

I presume the fix is probably something like this:

diff --git a/sdl/render.go b/sdl/render.go
index 6e2abab..45b67c9 100644
--- a/sdl/render.go
+++ b/sdl/render.go
@@ -1176,9 +1176,10 @@ func (renderer *Renderer) RenderGeometry(texture *Texture, vertices []Vertex, in
    _texture := texture.cptr()
    _vertices := (*C.SDL_Vertex)(unsafe.Pointer(&vertices[0]))
    _num_vertices := C.int(len(vertices))
-   _indices := (*C.int)(unsafe.Pointer(&indices[0]))
+   var _indices *C.int
    _num_indices := C.int(0)
    if indices != nil {
+       _indices = (*C.int)(unsafe.Pointer(&indices[0]))
        _num_indices = C.int(len(indices))
    }
    err = errorFromInt(int(C.SDL_RenderGeometry(renderer.cptr(), _texture, _vertices, _num_vertices, _indices, _num_indices)))
veeableful commented 2 years ago

Thanks for reporting the issue and providing the fix @advisoft! I have applied it and tagged a new patch release with v0.4.20.

advisoft commented 2 years ago

Thank you.