excaliburjs / Excalibur

🎮 Your friendly TypeScript 2D game engine for the web 🗡️
https://excaliburjs.com
BSD 2-Clause "Simplified" License
1.82k stars 189 forks source link

Error: Cannot build new ExcaliburGraphicsContext2D #3215

Closed dosfx closed 1 month ago

dosfx commented 1 month ago

Steps to Reproduce

Made a simple application:

import { Engine} from "excalibur";

const game = new Engine({
    width: 600,
    height: 600,
});

game.start();

Packaged and served with parcel.

Expected Result

Load the page and see the blue square

Actual Result

Don't even get the blue square in my mobile browser. Attached to USB I can see in the console:

[Warn] :  Excalibur could not load webgl for some reason (Could not compile fragment shader:

ERROR: Expression too complex.

Source:
1: #version 300 es
2: precision mediump float;
...many more lines
Uncaught Error: Cannot build new ExcaliburGraphicsContext2D for some reason!
    at new ExcaliburGraphicsContext2DCanvas (ExcaliburGraphicsContext2DCanvas.ts:146:13)
    at new Engine (Engine.ts:908:30)
    at gNOv5.excalibur (test.ts:3:14)
    at newRequire (index.90abf92b.js:71:24)
    at index.90abf92b.js:122:5
    at index.90abf92b.js:145:3

Environment

Current Workaround

Works if I do Flags.useCanvasGraphicsContext(); from: https://excaliburjs.com/docs/graphics-context/#canvas-support

eonarheim commented 1 month ago

@dosfx Wild! Thanks for the bug, can you share the hardware you're on too?

I might be able to reproduce it in BrowserStack

dosfx commented 1 month ago

Samsung Galaxy A53 5G cheers!

eonarheim commented 1 month ago

@dosfx I think I have a lead on this, turns out certain hardware has a max shader sizes! 🤯

I spotted a similar issue in pixi, theoretically should be a quick fix

https://github.com/pixijs/pixijs/pull/10613

eonarheim commented 1 month ago

Digging in this looks like a maximum number of branches in the shader program (if statements)

eonarheim commented 1 month ago

I found a device in BrowserStack I can reproduce, they don't have that exact combo but this seems to be the issue.

image

dosfx commented 1 month ago

That warning I copied in was basically all if statements, so that fits XD Sorry I should have grabbed more. I can hook it all back up again if you'd like and grab the whole thing.

eonarheim commented 1 month ago

@dosfx Merged to main! Should be deployed to alpha bits momentarily

dosfx commented 1 month ago

Confirmed works on my phone! :D