Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in render_frame, mac related? #474

Open
ivanlen opened this issue Jan 8, 2025 · 2 comments
Open

Error in render_frame, mac related? #474

ivanlen opened this issue Jan 8, 2025 · 2 comments

Comments

@ivanlen
Copy link

ivanlen commented Jan 8, 2025

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
Copy link
Author

ivanlen commented Jan 8, 2025

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)

Copy link
Contributor

github-actions bot commented Jan 8, 2025

Thank you for submitting your first issue to p5py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant