oakmound / oak

A pure Go game engine
Apache License 2.0
1.55k stars 83 forks source link

Quite a number of the examples don't work (on macOS) #162

Closed prologic closed 3 years ago

prologic commented 3 years ago

See:

prologic@Jamess-iMac
Sat Sep 11 13:03:29
~/tmp/oak
 (master) 130
$ go run examples/keyboard-test/main.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x40d3600]

goroutine 13 [running]:
image.(*RGBA).Bounds(0x0)
    /usr/local/Cellar/go/1.17/libexec/src/image/image.go:98
image/draw.clip({0x41ff7f0, 0x0}, 0xc00010d9a0, {0x41fe9e0, 0xc000078200}, 0xc00010d960, {0x0, 0x0}, 0xc00010d980)
    /usr/local/Cellar/go/1.17/libexec/src/image/draw/draw.go:85 +0x6f
image/draw.DrawMask({0x41ff7f0, 0x0}, {{0x0, 0x0}, {0x280, 0x1e0}}, {0x41fe9e0, 0xc000078200}, {0x0, 0x0}, ...)
    /usr/local/Cellar/go/1.17/libexec/src/image/draw/draw.go:117 +0xa5
golang.org/x/image/draw.DrawMask(...)
    /Users/prologic/go/pkg/mod/golang.org/x/image@v0.0.0-20201208152932-35266b937fa6/draw/draw.go:31
golang.org/x/image/draw.Copy({0x41ff7f0, 0x0}, {0x0, 0x0}, {0x41fe9e0, 0xc000078200}, {{0x0, 0x0}, {0x280, 0x1e0}}, ...)
    /Users/prologic/go/pkg/mod/golang.org/x/image@v0.0.0-20201208152932-35266b937fa6/draw/scale.go:28 +0x1e5
golang.org/x/image/draw.nnInterpolator.Transform({}, {0x41ff7f0, 0x0}, {0x3ff0000000000000, 0x0, 0x0, 0x0, 0x3ff0000000000000, 0x0}, {0x41fe9e0, ...}, ...)
    /Users/prologic/go/pkg/mod/golang.org/x/image@v0.0.0-20201208152932-35266b937fa6/draw/impl.go:113 +0x158
github.com/oakmound/oak/v3/shiny/driver/mtldriver.(*windowImpl).Draw(0xc0001abdd0, {0x3ff0000000000000, 0x0, 0x0, 0x0, 0x3ff0000000000000, 0x0}, {0x4200098, 0xc0000100c0}, {{0x0, ...}, ...}, ...)
    /Users/prologic/tmp/oak/shiny/driver/mtldriver/window.go:132 +0xb6
github.com/oakmound/oak/v3/shiny/driver/internal/drawer.Scale({0x4200278, 0xc0001240f0}, {{0x1, 0x0}, {0x0, 0x0}}, {0x4200098, 0xc0000100c0}, {{0x0, 0x0}, ...}, ...)
    /Users/prologic/tmp/oak/shiny/driver/internal/drawer/drawer.go:30 +0x110
github.com/oakmound/oak/v3/shiny/driver/mtldriver.(*windowImpl).Scale(0xc0001240f0, {{0x0, 0x0}, {0x280, 0x1e0}}, {0x4200098, 0xc0000100c0}, {{0x0, 0x0}, {0x280, ...}}, ...)
    /Users/prologic/tmp/oak/shiny/driver/mtldriver/window.go:144 +0x78
github.com/oakmound/oak/v3.(*Window).publish(0xc000014800)
    /Users/prologic/tmp/oak/drawLoop.go:62 +0x15c
github.com/oakmound/oak/v3.(*Window).drawLoop(0xc000014800)
    /Users/prologic/tmp/oak/drawLoop.go:22 +0x125
created by github.com/oakmound/oak/v3.(*Window).lifecycleLoop
    /Users/prologic/tmp/oak/lifecycle.go:36 +0x1c9
exit status 2

I haven't looked into why yet...

200sc commented 3 years ago

We have limited Mac testing, so thanks for catching this, I'll look into it tomorrow.

prologic commented 3 years ago

We have limited Mac testing, so thanks for catching this, I'll look into it tomorrow.

Let me know how I can help! I'm pretty good with Go, just too tired to look into it right now šŸ˜“

200sc commented 3 years ago

With limited checking, it seems like windowImpl.rgba is nil sometimes, and we assume it isn't in all of its draw logic. Adding a check to windowImpl.Draw in mtldriver moves the panic to windowImpl.Publish.

The logic for initializing some of the window components was only done after we got a size event back from the OS, which might not happen until after we start drawing. The commit above (on release/3.0.0-final and backported to a hotfix branch) initializes those values on window creation.

@prologic Would you mind checking that branch and confirming it works on your end as well? hotfix/mtldriver-init

prologic commented 3 years ago

This seems to have fixed a few cases I guess?

I was even able to run the complete playformer example (sort of) until I re-ran it and it crahsed immediately (race?):

(āŽˆ |local:default)
prologic@Jamess-iMac
Sun Sep 12 09:21:06
~/tmp/oak
 (master) 0
$ go run examples/platformer-tutorial/6-complete/complete.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x40e3300]

goroutine 68 [running]:
image.(*RGBA).Bounds(0x0)
    /usr/local/Cellar/go/1.17/libexec/src/image/image.go:98
image/draw.clip({0x41f6c70, 0x0}, 0xc00013d9a0, {0x41f5e20, 0xc000282040}, 0xc00013d960, {0x0, 0x0}, 0xc00013d980)
    /usr/local/Cellar/go/1.17/libexec/src/image/draw/draw.go:85 +0x6f
image/draw.DrawMask({0x41f6c70, 0x0}, {{0x0, 0x0}, {0x280, 0x1e0}}, {0x41f5e20, 0xc000282040}, {0x0, 0x0}, ...)
    /usr/local/Cellar/go/1.17/libexec/src/image/draw/draw.go:117 +0xa5
golang.org/x/image/draw.DrawMask(...)
    /Users/prologic/go/pkg/mod/golang.org/x/image@v0.0.0-20210628002857-a66eb6448b8d/draw/draw.go:31
golang.org/x/image/draw.Copy({0x41f6c70, 0x0}, {0x0, 0x0}, {0x41f5e20, 0xc000282040}, {{0x0, 0x0}, {0x280, 0x1e0}}, ...)
    /Users/prologic/go/pkg/mod/golang.org/x/image@v0.0.0-20210628002857-a66eb6448b8d/draw/scale.go:28 +0x1e5
golang.org/x/image/draw.nnInterpolator.Transform({}, {0x41f6c70, 0x0}, {0x3ff0000000000000, 0x0, 0x0, 0x0, 0x3ff0000000000000, 0x0}, {0x41f5e20, ...}, ...)
    /Users/prologic/go/pkg/mod/golang.org/x/image@v0.0.0-20210628002857-a66eb6448b8d/draw/impl.go:113 +0x158
github.com/oakmound/oak/v3/shiny/driver/mtldriver.(*windowImpl).Draw(0xc00068b5d0, {0x3ff0000000000000, 0x0, 0x0, 0x0, 0x3ff0000000000000, 0x0}, {0x41f7518, 0xc000280010}, {{0x0, ...}, ...}, ...)
    /Users/prologic/tmp/oak/shiny/driver/mtldriver/window.go:132 +0xb6
github.com/oakmound/oak/v3/shiny/driver/internal/drawer.Scale({0x41f76b0, 0xc0001160f0}, {{0x1, 0x0}, {0x0, 0x0}}, {0x41f7518, 0xc000280010}, {{0x0, 0x0}, ...}, ...)
    /Users/prologic/tmp/oak/shiny/driver/internal/drawer/drawer.go:30 +0x110
github.com/oakmound/oak/v3/shiny/driver/mtldriver.(*windowImpl).Scale(0xc0001160f0, {{0x0, 0x0}, {0x280, 0x1e0}}, {0x41f7518, 0xc000280010}, {{0x0, 0x0}, {0x280, ...}}, ...)
    /Users/prologic/tmp/oak/shiny/driver/mtldriver/window.go:144 +0x78
github.com/oakmound/oak/v3.(*Window).publish(0xc000014800)
    /Users/prologic/tmp/oak/drawLoop.go:62 +0x15c
github.com/oakmound/oak/v3.(*Window).drawLoop(0xc000014800)
    /Users/prologic/tmp/oak/drawLoop.go:22 +0x125
created by github.com/oakmound/oak/v3.(*Window).lifecycleLoop
    /Users/prologic/tmp/oak/lifecycle.go:36 +0x1c9
exit status 2
prologic commented 3 years ago

Also the keys in the platformer example don't seem to work?

200sc commented 3 years ago

Ok, it looks like I assumed it was just one problem too quickly : ) I'll go through every example and verify that they operate correctly and add needed fixes to that PR.

prologic commented 3 years ago

Happy to test/confirm here! Thanks! šŸ‘Œ

200sc commented 3 years ago

Added a couple of fixes, remaining issues I see:

Continuing to fix.

prologic commented 3 years ago

Sorry about all the work šŸ¤—

200sc commented 3 years ago

Ok, I'm going to leave joystick support for the existing issue (#87), but having run through all of the examples before and re-run through about half, including all those that previously failed, post fixes; give it another go, please @prologic, on release/3.0.0-final.

Several examples were already fixed between the beta branch that is HEAD of master and release/3.0.0-final, which is to be released shortly, pending final review, but in addition the standard osx rendering driver is more or less up to feature parity with the standard windows and linux drivers through this line of work.

prologic commented 3 years ago

This is really cool! šŸŽ‰ Of the ones that were broken for me, now work! šŸ‘Œ šŸ’Æ

Ii'll keep playing with this but I'm really happy šŸ¤—

200sc commented 3 years ago

Closing as the original problem is resolved.