RaspberryPiFoundation / editor-ui

Code Editor web component
https://editor-static.raspberrypi.org
Apache License 2.0
37 stars 8 forks source link

Uncaught exception when P5 sketch loads an image that does not exist #1025

Closed floehopper closed 1 month ago

floehopper commented 1 month ago

Steps to reproduce:

This doesn't seem to break anything in production, but the app completely breaks in development which isn't great.

  1. Create a new blank Python project (i.e. with no images available)
  2. Write P5 Sketch code that loads and draws a non-existent image, e.g.
from p5 import *

img = None

def setup():
    size(400, 200)
    global img
    img = load_image("does-not-exist.png")

def draw():
    image(img, 10, 25, 100 , 100)
    no_loop()

run()
  1. Click the "Run" button to run the P5 Sketch
  2. See that the image is not drawn on the output panel canvas
  3. See that there is an uncaught exception in the browser Developer Tools console

Initial investigation

The following function calls seem to be relevant:

load_image(): https://github.com/RaspberryPiFoundation/editor-ui/blob/ca69c291365422025c5e628c3800b83546b0f2f1/public/shims/processing/p5/p5-shim.js#L1700

loadImage(): See these docs

floehopper commented 1 month ago

It looks as if this is also resolved if the image is loaded in preload() as opposed to setup() as in #1024. Closing.