skelterjohn / go.wde

Windows, drawing and events for Go
217 stars 46 forks source link

Window.FlushImage crashes if called while minimised (on windows) #46

Closed sqweek closed 8 years ago

sqweek commented 9 years ago

Sensible code perhaps shouldn't be calling FlushImage while the window is not visible, but here we are. Easy to reproduce via wdetest:

resize 180 158
resize 0 0
panic: runtime error: index out of range

goroutine 21 [running]:
runtime.panic(0x4fb900, 0x5cc65c)
        c:/go/src/pkg/runtime/panic.c:279 +0x11f
github.com/AllenDang/w32.SetDIBitsToDevice(0xffffffff8d010c32, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5d02e0, ...)
        d:/code/go/src/github.com/AllenDang/w32/gdi32.go:458 +0x184
github.com/skelterjohn/go.wde/win.(*Window).blitImage(0xc0820b6000, 0xffffffff8d010c32, 0xc0820065c0)
        d:/code/go/src/github.com/skelterjohn/go.wde/win/win_windows.go:210 +0x1a0
github.com/skelterjohn/go.wde/win.(*Window).FlushImage(0xc0820b6000, 0x0, 0x0, 0x0)
        d:/code/go/src/github.com/skelterjohn/go.wde/win/win_windows.go:169 +0xc6
main.func┬À002()
        d:/code/go/src/github.com/skelterjohn/go.wde/wdetest/wdetest.go:141 +0x64d
created by main.wdetest
        d:/code/go/src/github.com/skelterjohn/go.wde/wdetest/wdetest.go:151 +0xa5

Easy to avoid by returning early from FlushImage when the window has bounds (0, 0), although it might make more sense to avoid resizing the backing image when minimised (since we'll presumably reallocate an image of exactly the same size when the window is restored).