home/ modules/ debugging-and-panic-recovery-in-p5live

Debugging and panic recovery in P5LIVE

  • learner can predict which P5LIVE edits trigger a softCompile versus a hardCompile, and structure sketch state to survive live edits without resetting
  • learner can identify and fix the six silent-failure classes in p5.js — missing background(), leaked transforms, stale class instances, wrong audio-reactivity wiring, undefined assets, and WEBGL origin shift — by reading canvas symptoms alone
  • learner can select and correctly wire one of P5LIVE's three audio-reactivity routes (p5.sound, HY5, embedded Strudel) and explain why the other two routes silently return zero in that configuration
  • learner can recover a broken or frozen P5LIVE sketch live by applying the minimal cleared-and-isolated skeleton, and explain which structural element prevents each common failure class

Take a seeded P5LIVE file that contains at least nine bugs, none of which throws a console error — a hardCompile trap (global mutable state reset when setup() or a global is edited), a missing background() causing trails, a leaked transform that accumulates across frames, a stale class-instance method edit that a softCompile won't hot-swap, a wrong audio-reactivity source yielding frozen zeros, a WEBGL-mode color/origin failure, a Hydra noise()/noize() name clash, a loadFont()/loadImage() called outside preload(), and an instance-mode sketch pasted into P5LIVE's global mode — plus one unbounded per-frame loop that freezes the tab and a mismatched sandbox/strudel comment-region delimiter. Without looking up solutions, diagnose each failure purely from the canvas symptom or the recompile behaviour, fix every bug, and restructure the surviving global state so the sketch survives live edits without resetting. Then, from memory, write the minimal cleared-and-isolated panic skeleton and annotate each structural line with the failure class it prevents. The final file must run error-free in P5LIVE, include one working audio-reactive element correctly wired to exactly one of the three routes (state which, and why the other two would read zero here), and — noting how COCODING renders locally per peer — flag any element that would look different for a co-coding collaborator.

This module addresses the professional reality of using P5LIVE mid-set: edits go live as you type, but the recompile model has limits that look like bugs, silent canvas failures give no stack trace, and a frozen tab can kill a performance. The ability to read a canvas as a diagnostic display — no exception, no error banner, just the visual result and your knowledge of the failure taxonomy — is what separates a working P5LIVE performer from one who restarts the page.

The arc begins with the recompile boundary, which is the most misunderstood aspect of P5LIVE’s hot-swap model. A softCompile replaces only the edited function body; a hardCompile restarts the entire sketch and resets every global. Knowing this boundary (“editing setup() or a global triggers hardCompile”) determines how to structure performance state: mutable counters, particle arrays, and evolving variables belong inside draw(), not at the global scope. Class-method edits introduce a further wrinkle — old instances keep running the old code until the next hardCompile — so the fix is either to force a re-emit or to avoid stateful class patterns for live-evolving parameters.

From there the module maps the six silent-failure classes. None of these throw a JavaScript exception; diagnosis is purely visual. Missing background() produces trail accumulation — shapes from every prior frame stack on screen. A leaked transform (translate or rotate outside push/pop) drifts or spins faster each frame. Stale class instances show old behaviour despite the edit. Wrong audio-reactivity wiring freezes the reactive parameter at zero with no console complaint, because P5LIVE has three incompatible audio routes (p5.sound, HY5/Hydra bridge, embedded Strudel) and none silently bridges to another. A loadFont() outside preload() silently produces no text. WEBGL mode shifts the canvas origin to center and requires texture() before shapes render colour — broken 2D assumptions fail silently.

The audio-reactivity section requires committing to one route: for p5.sound, call setupAudio(true) in setup and updateAudio() at the top of draw; for HY5, run Hydra with detectAudio:true and read up to 8 bins from a.fft; for embedded Strudel, wire via the .p5live(()=>{}) callback. Using a.fft in P5LIVE without an active Hydra session returns undefined. The HY5 name-clash note is a prerequisite for using Hydra and p5 together: Hydra’s noise() is aliased to noize() inside P5LIVE to avoid collision with p5’s built-in noise().

The capstone exercises all four objectives under no-scaffold conditions. The learner receives a seeded bug file, diagnoses and fixes every silent failure — the six canvas-visible classes plus the frozen-tab loop, the noise/noize clash, the preload/asset trap, the instance-vs-global-mode paste, and a mismatched sandbox/strudel comment region — then restructures global state so the sketch survives live edits, and finally writes the panic recovery skeleton from memory. The annotation requirement forces explicit reasoning: each structural line of the skeleton is labelled with the failure class it prevents. The required audio element confirms one reactivity route is correctly wired and not silently frozen, and the learner must name the route and explain why the other two would read zero in that configuration; the COCODING flag confirms they understand which elements render locally per peer.

The supporting atoms enrich rather than gate. p5js-visual-first-creative-coding frames why P5LIVE suits a performance rig; p5js-push-pop-transformations and p5js-webgl-coordinate-origin provide supplementary reference for the two most common silent failures; p5js-local-server-requirement is a grounding detail for anyone running sketches outside the hosted P5LIVE environment.

Atoms in this module

Required — these gate the capstone

P5LIVE softCompile only replaces changed functions, leaving global-variable or setup edits to trigger a full hardCompile
Concept L1 Foundations H
Existing class instances in P5LIVE retain old methods after a softCompile; only newly-constructed instances get the updated code
Misconception L1 Foundations H
p5.js is a state machine where fill, stroke, and transform calls persist until overridden, so wrapping elements in push/pop prevents transform accumulation
Principle L1 Foundations H
P5LIVE audio-reactivity has three incompatible sources (p5.sound, HY5, embedded Strudel) and none is the rig's 4-bin a.fft contract
Concept L1 Foundations HJ
In P5LIVE with HY5 loaded, Hydra's noise() is aliased to noize() to avoid collision with p5's built-in noise()
Fact L1 Foundations H
P5LIVE sandbox and strudel regions must use matched open/close comment delimiters at top level, not inside functions
Procedure L1 Foundations H
p5.js asset-loading functions (loadFont, loadImage) are asynchronous and must be called in preload() or given a callback to avoid undefined references
Procedure L1 Foundations H
P5LIVE runs p5 in global mode; instance-mode sketches (function sketch(p){}) must be rewritten before they work
Fact L1 Foundations H
p5's WEBGL renderer moves the origin to the canvas center and needs texture()/material before shapes show color
Concept L1 Foundations H
In a P5LIVE COCODING session the code syncs but each peer renders locally, so sketches depending on local mic/webcam/MIDI look different per machine
Concept L1 Foundations H
A failed P5LIVE compile leaves the last good frame visible rather than blanking the canvas
Concept L5 Voice H
Many p5.js bugs produce no exception and manifest only as wrong canvas output
Concept L5 Voice H
background() must be the first call in p5.js draw() to clear each frame; placing it after shapes wipes them
Principle L5 Voice H
Transforms in p5.js draw() must be enclosed in push()/pop() or they accumulate across every frame
Principle L5 Voice H
P5LIVE has three distinct audio reactivity sources and no automatic 4-bin a.fft rig bridge
Concept L5 Voice HJ
p5.js claims the name noise() so Hydra's noise function must be called noize() inside P5LIVE
Fact L5 Voice H
A P5LIVE edit that won't take effect is usually a recompile-scope issue — class-method or global-state edits do not hot-swap live instances
Concept L5 Voice H
An unbounded loop or heavy per-frame work freezes the P5LIVE tab because p5 runs single-threaded on the main thread
Principle L5 Voice H
A minimal cleared-and-isolated setup()/draw() skeleton is the safe P5LIVE recovery sketch because it avoids every common failure at once
Procedure L5 Voice H
WEBGL mode in p5.js centers the origin and requires texture() for color, silently breaking 2D assumptions
Concept L5 Voice H

Supporting — enrichment, not gating

p5.js carries Processing's accessibility goal to the browser as a visual-first creative-coding environment
Concept L0 Orientation H
push() and pop() isolate transformations so they do not accumulate globally in p5.js
Procedure L2 First instrument H
p5.js sketches that load external files require a local web server to avoid cross-origin errors
Fact L1 Foundations H
In p5.js WEBGL mode the coordinate origin is at the canvas center, not the top-left
Concept L2 First instrument HG