Menu

When the Canvas Goes Black: WebGL Context Loss on Cheap Android Phones
πŸ“°

When the Canvas Goes Black: WebGL Context Loss on Cheap Android Phones

DEV Community: mobileΒ·Eka PutriΒ·2 days ago
#37N2dp8S
#devtomobile#devto#dev#phone#canvas
Reading 0:00
15s threshold

A friend handed me an old Android phone last week with a web game frozen on a black rectangle. The HUD still updated β€” score, timer, a pause button β€” but the play field was gone and the console said nothing. A reload fixed it for four minutes.

That is what WebGL context loss looks like from outside. The driver decides it needs the memory back, the browser drops the context, and every gl call afterwards returns INVALID_OPERATION while the canvas holds its last frame or goes blank. On a 3 GB phone with a dozen tabs open it is routine.

Only the WebGL layer dies, which is the giveaway: a DOM overlay keeps repainting, so the bug reads as a rendering glitch rather than a lost context. I listen for it by name now, and preventDefault() is the line that makes a restore possible at all.

canvas . addEventListener ( 'webglcontextlost' , e => { e . preventDefault ( ) ; pauseRound ( ) ; } ) ; canvas .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.