p5
p5 copied to clipboard
Error in `render_frame`, mac related?
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)
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)
Thank you for submitting your first issue to p5py
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/