home/ atoms/ p5live-frozen-tab-unbounded-loop

An unbounded loop or heavy per-frame work freezes the P5LIVE tab because p5 runs single-threaded on the main thread

p5.js executes draw() and any loops synchronously on the browser’s main thread. A while loop with no exit, or a large per-frame for over pixels[] or a big particle array, blocks the event loop: the tab hangs, frame rate drops to zero, and recompile-on-save stops responding. Because there is no exception, it reads as a dead editor. The fixes are to bound every loop, cache heavy static work into a createGraphics buffer drawn once, and lower pixelDensity(1). If already frozen, stop the sketch or reload the IDE and paste a known-good fallback.

Examples

while(x < 10){ ellipse(x,0,5,5); } with no x++ freezes the tab. Move a costly full-pixels[] pass into a cached createGraphics layer rendered once instead of every frame.

Assessment

A P5LIVE sketch causes the browser tab to hang with fps at zero and no error. Explain why single-threaded execution makes this possible and give two ways to prevent or recover from it.

“Bound every loop; move heavy work into a cached `createGraphics` buffer; lower `pixelDensity(1)`”
context/ · L5-debug/p5live.md · chunk 1