p5 icon indicating copy to clipboard operation
p5 copied to clipboard

Error in `render_frame`, mac related?

Open ivanlen opened this issue 1 year ago • 3 comments

Describe the bug I get a java error when I try to render a frame.

To Reproduce Either running a python script or using the notebook extension

import py5
import numpy as np

canvas_size = 1000
pad = 10

points = pad / 2 + np.random.random((100, 2)) * (canvas_size - pad)


def draw(s: py5.Sketch):
    py5.background(255)
    py5.stroke(0)
    # set width of line
    py5.stroke_weight(1)
    for i in range(len(points) - 1):
        py5.line(points[i][0], points[i][1], points[i + 1][0], points[i + 1][1])

img = py5.render_frame(draw, canvas_size, canvas_size)

I get this error

py5 encountered an error in your code:

File "PSurfaceNone.java", line 356, in processing.core.PSurfaceNone$AnimationThread.run

Exception: Java Exception

The above exception was the direct cause of the following exception:

java.lang.NullPointerException: java.lang.NullPointerException: Cannot invoke "processing.core.PGraphics.background(int)" because "this.g" is null

Expected behavior No error

System information:

  • p5==0.8.4
  • Python 3.11.0
  • Operating system: MacOs 14.6.1 (23G93)

ivanlen avatar Jan 08 '25 01:01 ivanlen

Note that using run_sketch in notebook is working, this works:

import py5
import numpy as np

canvas_size = 1000
pad = 10

points = pad / 2 + np.random.random((100, 2)) * (canvas_size - pad)


# draw lines joining the points
def setup():
    py5.size(canvas_size, canvas_size, py5.P2D)


def draw():
    py5.background(255)
    py5.stroke(0)
    # set width of line
    py5.stroke_weight(1)
    for i in range(len(points) - 1):
        py5.line(points[i][0], points[i][1], points[i + 1][0], points[i + 1][1])


py5.run_sketch(block=False)

ivanlen avatar Jan 08 '25 01:01 ivanlen

Thank you for submitting your first issue to p5py

github-actions[bot] avatar Jan 08 '25 01:01 github-actions[bot]

import py5

Cheers @ivanlen !

I'm afraid you mixed up the project repos, the names are similar! Here we are on the p5py/p5 project, if you still have this issue you might want to ask for help at the py5 project instead:

https://github.com/py5coding/py5generator/discussions/

villares avatar Aug 07 '25 13:08 villares