jdf / Processing.py-Bugs

A home for all bugs and feature requests about Python Mode for the Processing Development Environment.
41 stars 8 forks source link

strokeWeight(), stroke() and other attributes return NullPointerException when called outside of a built in function. #315

Closed ContemptibleCentreUser closed 3 years ago

ContemptibleCentreUser commented 3 years ago

Given any built-in function is called (such as draw() or mouseClicked), it seems attributes such as strokeWeight(), stroke() raise a NullPointerException error. For example, when

def setup():
    size(400,400)

stroke(0, 0, 0)
strokeWeight(5)
circle(100, 100, 100)

is run, it returns a not very fun looking error:

processing.app.SketchException: java.lang.NullPointerException
    at processing.core.PApplet.stroke(PApplet.java:14579)
    at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)
    at org.python.core.PyObject.__call__(PyObject.java:534)
    at org.python.core.PyObject.__call__(PyObject.java:540)
    at org.python.core.PyMethod.__call__(PyMethod.java:171)
    at org.python.pycode._pyx194.f$0(sketch_210426a.pyde:1)
    at org.python.pycode._pyx194.call_function(sketch_210426a.pyde)
    at org.python.core.PyTableCode.call(PyTableCode.java:171)
    at org.python.core.PyCode.call(PyCode.java:18)
    at org.python.core.Py.runCode(Py.java:1614)
    at org.python.core.Py.exec(Py.java:1658)
    at org.python.pycode._pyx193.f$0(/var/folders/vf/3zy00t252_372n6n1n060tc00000gn/T/sketch_210426a7845311776409314445/sketch_210426a.pyde:96)
    at org.python.pycode._pyx193.call_function(/var/folders/vf/3zy00t252_372n6n1n060tc00000gn/T/sketch_210426a7845311776409314445/sketch_210426a.pyde)
    at org.python.core.PyTableCode.call(PyTableCode.java:171)
    at org.python.core.PyCode.call(PyCode.java:18)
    at org.python.core.Py.runCode(Py.java:1614)
    at org.python.core.Py.exec(Py.java:1658)
    at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)
    at jycessing.PAppletJythonDriver.processSketch(Unknown Source)
    at jycessing.PAppletJythonDriver.findSketchMethods(Unknown Source)
    at jycessing.Runner.runSketchBlocking(Unknown Source)
    at jycessing.mode.run.SketchRunner.lambda$startSketch$3(Unknown Source)
    at java.lang.Thread.run(Thread.java:748)

    at jycessing.mode.run.SketchRunner.convertPythonSketchError(Unknown Source)

Contrastingly, if I run

stroke(204, 102, 0)
circle(30, 20, 100)

With no built-in functions, the code works as intended. A bit of a disclaimer, I am a bit of a newbie and this might just be an an oversight of mine.

villares commented 3 years ago

Hi @ContemptibleCentreUser,

I believe this is somewhat expected behaviour. You are not suppoded to "mix static and dynamic modes". Static mode is without setup() and draw(). If you create setup() and/or draw() you are supposed to have all drawing functions inside them.