Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile/gl: GetAttachedShaders panics with no shaders attached #11980

Closed
shazow opened this issue Aug 1, 2015 · 2 comments
Closed

x/mobile/gl: GetAttachedShaders panics with no shaders attached #11980

shazow opened this issue Aug 1, 2015 · 2 comments

Comments

@shazow
Copy link
Contributor

shazow commented Aug 1, 2015

When calling gl.GetAttachedShaders(program) on a program that has no shaders attached, an avoidable panic occurs.

panic: runtime error: index out of range

goroutine 21 [running]:
golang.org/x/mobile/gl.GetAttachedShaders(0x1, 0x0, 0x0, 0x0)
    /Users/shazow/local/go1.5/src/golang.org/x/mobile/gl/gl.go:860 +0x1d0

We get the number of attached shaders with shadersLen := GetProgrami(p, ATTACHED_SHADERS) and allocate the buffer based on that number, but we never check if it's zero.

Simplest fix would be something like this:

func GetAttachedShaders(p Program) []Shader {
    shadersLen := GetProgrami(p, ATTACHED_SHADERS)
+   if shadersLen == 0 {
+       return []Shader{}
+   }
    var n C.GLsizei
    buf := make([]C.GLuint, shadersLen)
    ...

This is on go version devel +71832ff Fri Jul 3 21:39:04 2015 +0000 darwin/amd64 with the latest x/mobile (9865dd0).

(Happy to do a CL if that would be more convenient.)

@crawshaw
Copy link
Member

crawshaw commented Aug 3, 2015

Thanks. I'm happy to either fix a bug (especially one this clearly described) or review a CL, whichever is more convenient/fun for you.

@gopherbot
Copy link

CL https://golang.org/cl/13090 mentions this issue.

@rsc rsc added this to the Unreleased milestone Aug 6, 2015
@golang golang locked and limited conversation to collaborators Aug 9, 2016
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 10, 2021
Fixes golang/go#11980

Change-Id: I914234bfd3c39e2832db49d8f389305d919e6045
Reviewed-on: https://go-review.googlesource.com/13090
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 11, 2021
Fixes golang/go#11980

Change-Id: I914234bfd3c39e2832db49d8f389305d919e6045
Reviewed-on: https://go-review.googlesource.com/13090
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants