Skip to content

Infinite loop detection triggers on await loadImage etc in setup #4295

Open

Description

@gohai

p5.js version

2.3.2

What is your operating system?

Mac OS

Web browser and version

152.0.7977.82

Actual Behavior

Using a for-loop inside setup that loads resources (e.g. loadImage):

let fns = ["a.jpg", "b.jpg", "c.jpg"];
let imgs = [];

async function setup() {
  for (let i=0; i < fns.length; i++) {
    imgs.push(await loadImage(fns[i]));
  }
}

Expected Behavior

The could should run, as it isn't an infinite loop, and await loadImage() the expected pattern to use with p5.js 2.0.

Steps to reproduce

See above.

Activity

  1. added
    BugError or unexpected behaviors
    on Sep 7, 2026
  2. sarthaklole commented on Sep 10, 2026

    @sarthaklole

    hi
    I like to take this issue

  3. ANUBHAVSINGH30 commented on Sep 14, 2026

    @ANUBHAVSINGH30

    Dug into this further — the crash traces to client/modules/IDE/components/Editor/index.jsx around line 222:

    js
    const errorObj = { stack: firstError.data[0].toString() };

    When the await-in-loop sketch throws an error, it looks like firstError.data[0] ends up undefined when this runs, causing Cannot read properties of undefined (reading 'toString') and crashing the whole Editor component — rather than just showing a normal console error. There are likely two things going on: whatever's actually throwing when await is used inside a for loop in setup() (the root cause), and this line not defensively checking firstError.data[0] exists before calling .toString() on it (which turns a normal error into a full component crash). Happy to dig into what's actually throwing on the loop side if that's useful, or take a stab at hardening this line as a quick follow-up fix.

  4. ANUBHAVSINGH30 commented on Sep 25, 2026

    @ANUBHAVSINGH30

    Since finding this, I looked into the crash further and traced it to a specific line in client/modules/IDE/components/Editor/index.jsx:

    js
    const errorObj = { stack: firstError.data[0].toString() };

    This throws when firstError.data[0] is undefined, turning what should be a normal console error into a full Editor crash. I'd like to submit a defensive fix for this specific line (adding a safety check before calling .toString()) — separate from investigating the root cause of what's throwing in the loop-protect logic. Could I get assigned to this, or is it okay to just open a PR for this specific fix?

  5. yashgoyal0110 commented on Oct 3, 2026

    @yashgoyal0110
    Contributor

    Hey @clairep94
    can i take this one?

  6. dhowe commented on Oct 14, 2026

    @dhowe

    students are reporting the same issue here - any status on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugError or unexpected behaviors

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions