fogleman / primitive

Reproducing images with geometric primitives.
https://primitive.lol/
MIT License
12.35k stars 608 forks source link

Edge case bug? #18

Closed ropery closed 7 years ago

ropery commented 7 years ago

Looks like 0 is passed to Intn?

panic: invalid argument to Intn

goroutine 8 [running]:
panic(0x539800, 0xc42000edb0)
    /usr/lib/go/src/runtime/panic.go:500 +0x1a1
math/rand.(*Rand).Intn(0xc4200104a0, 0x0, 0x0)
    /usr/lib/go/src/math/rand/rand.go:116 +0xd0
github.com/fogleman/primitive/primitive.NewRandomEllipse(0x1, 0x1, 0xc4200104a0, 0x0)
    /usr/lib/go/src/github.com/fogleman/primitive/primitive/ellipse.go:22 +0x8d
github.com/fogleman/primitive/primitive.(*Model).RandomState(0xc420072210, 0xc420018600, 0x3, 0x80, 0xc4200104a0, 0x20)
    /usr/lib/go/src/github.com/fogleman/primitive/primitive/model.go:198 +0x3bd
github.com/fogleman/primitive/primitive.(*Model).BestRandomState(0xc420072210, 0xc420018600, 0x3, 0x80, 0x64, 0xc4200104a0, 0x0)
    /usr/lib/go/src/github.com/fogleman/primitive/primitive/model.go:179 +0x7e
github.com/fogleman/primitive/primitive.(*Model).BestHillClimbState(0xc420072210, 0xc420018600, 0x3, 0x80, 0x64, 0x64, 0x2, 0xc4200104a0, 0x0)
    /usr/lib/go/src/github.com/fogleman/primitive/primitive/model.go:162 +0xcf
github.com/fogleman/primitive/primitive.(*Model).runWorker(0xc420072210, 0x3, 0x80, 0x64, 0x64, 0x2, 0xc42005a180)
    /usr/lib/go/src/github.com/fogleman/primitive/primitive/model.go:154 +0x234
created by github.com/fogleman/primitive/primitive.(*Model).runWorkers
    /usr/lib/go/src/github.com/fogleman/primitive/primitive/model.go:136 +0x13b
fogleman commented 7 years ago

What image and arguments did you run with?

ropery commented 7 years ago

I ran this in a batch job; didn't really catch the image being processed that generated this error. These are small images downloaded then passed to primitive. Of the hundreds of images, on which the same arguments are used, this is the one single image that produced this error. Since randomness is involved, I thought it might just be an edge case of 0.

Edit: OK I checked my "backlog" and it's a dummy JPEG of size 1x1

JPEG 1x1 1x1+0+0 8-bit Gray 256c 160B 0.000u 0:00.000

Running primitive on it thousands times over has not reproduced the panic. Very strange. I doubt anyone else has encountered this. Feel free to close the issue.

fogleman commented 7 years ago

I suspected a tiny image. I think some other code changes fixed it anyway.