I am working through the excercises in the Go language tour and I have hit a snag that I can't figure out. I'm doing Exercise: Slices
and I am getting this error:
256 x 256
panic: runtime error: index out of range
goroutine 1 [running]:
main.Pic(0x10000000100, 0x3, 0x417062, 0x4abf70)
/tmpfs/gosandbox-08a27793_4ffc9f4a_3b917355_ef23793d_c15d58cc/prog.go:9 +0xa0
tour/pic.Show(0x400c00, 0x40caa2)
go/src/pkg/tour/pic/pic.go:20 +0x2d
main.main()
/tmpfs/gosandbox-08a27793_4ffc9f4a_3b917355_ef23793d_c15d58cc/prog.go:20 +0x25
Here is my code:
package main
import "tour/pic"
func Pic(dx, dy int) [][]uint8 {
fmt.Printf("%d x %d
", dx, dy)
pixels := make([][]uint8, 0, dy)
for y := 0; y < dy; y++ {
pixels[y] = make([]uint8, 0, dx)
for x := 0; x < dx; x++ {
pixels[y][x] = uint8(x*y)
}
}
return pixels
}
func main() {
pic.Show(Pic)
}
For the life of me I can't find the issue!