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

getting a webgl context fails on macOS #57

Open
hajimehoshi opened this issue Apr 30, 2024 · 8 comments
Open

getting a webgl context fails on macOS #57

hajimehoshi opened this issue Apr 30, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@hajimehoshi
Copy link
Contributor

hajimehoshi commented Apr 30, 2024

  1. Create this test (main_test.go)
package main_test

import (
	"syscall/js"
	"testing"
)

func TestWebGL(t *testing.T) {
	window := js.Global().Get("window")
	document := window.Get("document")
	body := document.Get("body")
	canvas := document.Call("createElement", "canvas")
	body.Call("appendChild", canvas)
	if context := canvas.Call("getContext", "2d"); !context.Truthy() {
		t.Fatal("getContext('2d') failed")
	}
	if context := canvas.Call("getContext", "webgl"); !context.Truthy() {
		t.Fatal("getContext('webgl') failed")
	}
}
  1. Run the test
GOOS=js GOARCH=wasm go test . 

The test fails:

--- FAIL: TestWebGL (0.01s)
    main_test.go:18: getContext('webgl') failed
FAIL
exit with status 1
FAIL    github.com/hajimehoshi/ebiten/v2/examples/test  0.755s
FAIL

The test fails even with WASM_HEADLESS=off.

My environment is:

                    'c.          [email protected] 
                 ,xNMM.          ------------------------------------- 
               .OMMMMo           OS: macOS 14.4 23E214 arm64 
               OMMM0,            Host: Mac15,6 
     .;loddo:' loolloddol;.      Kernel: 23.4.0 
   cKMMMMMMMMMMNWMMMMMMMMMM0:    Uptime: 42 days, 10 hours, 10 mins 
 .KMMMMMMMMMMMMMMMMMMMMMMMWd.    Packages: 135 (brew) 
 XMMMMMMMMMMMMMMMMMMMMMMMX.      Shell: zsh 5.9 
;MMMMMMMMMMMMMMMMMMMMMMMM:       Resolution: 1800x1169 
:MMMMMMMMMMMMMMMMMMMMMMMM:       DE: Aqua 
.MMMMMMMMMMMMMMMMMMMMMMMMX.      WM: Quartz Compositor 
 kMMMMMMMMMMMMMMMMMMMMMMMMWd.    WM Theme: Blue (Light) 
 .XMMMMMMMMMMMMMMMMMMMMMMMMMMk   Terminal: vscode 
  .XMMMMMMMMMMMMMMMMMMMMMMMMK.   CPU: Apple M3 Pro 
    kMMMMMMMMMMMMMMMMMMMMMMd     GPU: Apple M3 Pro 
     ;KMMMMMMMWXXWMMMMMMMk.      Memory: 3640MiB / 18432MiB 
       .cooc,.    .,coo:.

My wasmbrowsertest version is 6e494bb.

@hajimehoshi hajimehoshi changed the title getting a webgl context is not found on macOS getting a webgl context fails on macOS Apr 30, 2024
@agnivade
Copy link
Owner

Hmm.. I don't have a mac. But I will see if I can find something.

@agnivade agnivade added the bug Something isn't working label May 3, 2024
@agnivade
Copy link
Owner

agnivade commented May 3, 2024

@hajimehoshi - does it work if you manually paste the commands in a browser console? I just tried the following and got null for webgl

> let cc = document.createElement("canvas")
< undefined
> cc.getContext("2d")
< CanvasRenderingContext2D {canvas: canvas, globalAlpha: 1, globalCompositeOperation: 'source-over', filter: 'none', imageSmoothingEnabled: true, …}
> cc.getContext("webgl")
< null

@hajimehoshi
Copy link
Contributor Author

hajimehoshi commented May 3, 2024

The result was the same on the console.

EDIT: skipping to get 2d canvas changed the result:

image

@hajimehoshi
Copy link
Contributor Author

hajimehoshi commented May 3, 2024

Hm, apparently this is the same on Windows

> cat .\examples\test\main_test.go
package main_test

import (
        "syscall/js"
        "testing"
)

func TestWebGL(t *testing.T) {
        window := js.Global().Get("window")
        document := window.Get("document")
        body := document.Get("body")
        canvas := document.Call("createElement", "canvas")
        body.Call("appendChild", canvas)
        if context := canvas.Call("getContext", "webgl"); !context.Truthy() {
                t.Fatal("getContext('webgl') failed")
        }
}

> & (Get-Process -Id $PID).Path { $env:GOOS="js"; $env:GOARCh="wasm"; go test -exec="\\Mac\Home\ebiten\wasmbrowsertest.exe" .\examples\test\ }
--- FAIL: TestWebGL (0.00s)
    main_test.go:18: getContext('webgl') failed
FAIL
exit with status 1
FAIL    github.com/hajimehoshi/ebiten/v2/examples/test  1.130s
FAIL

@agnivade
Copy link
Owner

agnivade commented May 3, 2024

Ok, so it's a chromedp thing: chromedp/chromedp#1190. I'll take a deeper look.

@agnivade
Copy link
Owner

@hajimehoshi - Could you try with this branch: https://github.com/agnivade/wasmbrowsertest/tree/webgl and see if this helps? Unfortunately, my laptop doesn't support webgl so it's a bit difficult for me.

@hajimehoshi
Copy link
Contributor Author

Hmm, this never returns...

hajimehoshi@Hajimes-MacBook-Pro wasmtest % cat main_test.go 
package main_test

import (
        "syscall/js"
        "testing"
)

func TestWebGL(t *testing.T) {
        window := js.Global().Get("window")
        document := window.Get("document")
        body := document.Get("body")
        canvas := document.Call("createElement", "canvas")
        body.Call("appendChild", canvas)
        if context := canvas.Call("getContext", "2d"); !context.Truthy() {
                t.Fatal("getContext('2d') failed")
        }
        if context := canvas.Call("getContext", "webgl"); !context.Truthy() {
                t.Fatal("getContext('webgl') failed")
        }
}
hajimehoshi@Hajimes-MacBook-Pro wasmtest % GOOS=js GOARCH=wasm go test .

@agnivade
Copy link
Owner

Ugh .. sorry about that. I have a strong suspicion that it's got to do with some flag that is disabled by default in the headless Chrome, but works in the normal browser instance. But since I don't have a box to repro this, it is difficult for me.

I think this issue isn't even related to wasmbrowsertest. You might be able to get a standalone repro with just using chromedp, by running a piece of JS. If we can get to that, then it becomes easier to work on it. And even possibly report to chromedp team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants