I am using the latest version of py5 (0.10.6). Its associated py5_tools was used to install JavaFX on my Windows 11 operating system. The following code run in the Thonny editor fails on Windows 11; a window is created but there is no title and there is an accompanying error message. I am unable to add any controls to it. The same code runs without error on MacOS. I am unable to find where PSurfaceFX$ResizableCanvas is cast to a java.awt.Canvas which is apparently the source of the error. PSurfaceFX.java is located here:https://github.com/processing/processing4-javafx and ResizableCanvas is one of its classes. I will be unable to add any controls to this window until the error is fixed. I can’t figure out why there is a cast of a javafx canvas to one of the old awt canvases; as far as I am aware it inherits nothing from it. Furthermore, why won’t it run on Windows 11 when it works ok on Mac.
java.lang.ClassCastException: class processing.javafx.PSurfaceFX$ResizableCanvas cannot be cast to class java.awt.Canvas (processing.javafx.PSurfaceFX$ResizableCanvas is in unnamed module of loader ‘app’; java.awt.Canvas is in module java.desktop of loader ‘bootstrap’)
java.lang.ClassCastException: class processing.javafx.PSurfaceFX$ResizableCanvas cannot be cast to class java.awt.Canvas (processing.javafx.PSurfaceFX$ResizableCanvas is in unnamed module of loader 'app'; java.awt.Canvas is in module java.desktop of loader 'bootstrap')
at py5.core.Sketch.setup(Sketch.java:195)
at processing.core.PApplet.handleDraw(PApplet.java:2051)
at processing.javafx.PSurfaceFX$1.handle(Unknown Source)
at processing.javafx.PSurfaceFX$1.handle(Unknown Source)
at javafx.graphics/com.sun.scenario.animation.shared.TimelineClipCore.visitKeyFrame(TimelineClipCore.java:239)
at javafx.graphics/com.sun.scenario.animation.shared.TimelineClipCore.playTo(TimelineClipCore.java:197)
at javafx.graphics/javafx.animation.Timeline.doPlayTo(Timeline.java:172)
at javafx.graphics/javafx.animation.AnimationAccessorImpl.playTo(AnimationAccessorImpl.java:39)
at javafx.graphics/com.sun.scenario.animation.shared.InfiniteClipEnvelope.timePulse(InfiniteClipEnvelope.java:104)
at javafx.graphics/javafx.animation.Animation.doTimePulse(Animation.java:1189)
at javafx.graphics/javafx.animation.Animation$1.lambda$timePulse$0(Animation.java:207)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics/javafx.animation.Animation$1.timePulse(Animation.java:206)
at javafx.graphics/com.sun.scenario.animation.AbstractPrimaryTimer.timePulseImpl(AbstractPrimaryTimer.java:343)
at javafx.graphics/com.sun.scenario.animation.AbstractPrimaryTimer$MainLoop.run(AbstractPrimaryTimer.java:266)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:571)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:555)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:548)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(QuantumToolkit.java:353)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:840)
Graphics Device initialization failed for : d3d, sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
at com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(QuantumRenderer.java:283)
at com.sun.javafx.tk.quantum.QuantumToolkit.init(QuantumToolkit.java:254)
at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:264)
at com.sun.javafx.perf.PerformanceTracker.logEvent(PerformanceTracker.java:100)
at javafx.scene.Node.(Node.java:417)
at processing.javafx.PGraphicsFX2D$FontCache.(Unknown Source)
at processing.javafx.PGraphicsFX2D.(Unknown Source)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at processing.core.PApplet.makeGraphics(PApplet.java:1896)
at processing.core.PApplet.createPrimaryGraphics(PApplet.java:1975)
at processing.core.PApplet.initSurface(PApplet.java:10170)
at processing.core.PApplet.runSketch(PApplet.java:10131)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:95)
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
at java.base/java.lang.Thread.run(Thread.java:840)
java.lang.ExceptionInInitializerError
at processing.javafx.PGraphicsFX2D$FontCache.(Unknown Source)
at processing.javafx.PGraphicsFX2D.(Unknown Source)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at processing.core.PApplet.makeGraphics(PApplet.java:1896)
at processing.core.PApplet.createPrimaryGraphics(PApplet.java:1975)
at processing.core.PApplet.initSurface(PApplet.java:10170)
at processing.core.PApplet.runSketch(PApplet.java:10131)
Caused by: java.lang.RuntimeException: No toolkit found
at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:276)
at com.sun.javafx.perf.PerformanceTracker.logEvent(PerformanceTracker.java:100)
at javafx.scene.Node.(Node.java:417)
… 11 more
Java exception thrown by Sketch.runSketch:
java.lang.RuntimeException
Configuration:
W10
Thonny 4.1.7
Thonny -py5Mode 0.4.7.a0
Python 3.13.2
py5 0.10.6.a0
Other code works.
I tried this from example code (with modifications required):
MandelBrot Code Python < Click to expand!
# Uses Imported mode for py5
"""
The Mandelbrot
Set
by Daniel Shiffman.
Simple rendering of the Mandelbrot set.
"""
size(640, 360)
# Establish a range of values on the complex plane
# A different range will allow us to "zoom" in or out on the fractal
xmin = -3
ymin = -1.25
w = 5
h = 2.5
background(255)
# Make sure we can write to the pixels[] array.
# Only need to do this once since we don't do any other drawing.
load_pixels()
# Maximum number of iterations for each point on the complex plane
maxiterations = 100
# x goes from xmin to xmax
xmax = xmin + w
# y goes from ymin to ymax
ymax = ymin + h
# Calculate amount we increment x,y for each pixel
dx = float(xmax - xmin) / (width)
dy = float(ymax - ymin) / (height)
# Start y
y = ymin
for j in range(height):
# Start x
x = xmin
for i in range(width):
# Now we test, as we iterate z = z^2 + cm does z tend towards infinity?
a = x
b = y
n = 0
while n < maxiterations:
aa = a * a
bb = b * b
twoab = 2.0 * a * b
a = aa - bb + x
b = twoab + y
# Infinty in our finite world is simple, let's just consider it 16
if aa + bb > 16.0:
break # Bail
n += 1
# We color each pixel based on how long it takes to get to infinity
# If we never got there, let's pick the color black
if n == maxiterations:
pixels[i + j * width] = color(0)
else:
# Gosh, we could make fancy colors here if we wanted
pixels[i + j * width] = color(n * 16 % 255)
x += dx
y += dy
update_pixels()
Setting all this up was a challenge!
Too many leftovers (old code, paths, environment variables, etc.) and I had to clean house first.
Make sure that you have JavaFX installed. There are instructions in the reference below. You can then check your libraries to confirm that it was really done.
If you still have trouble I can try and retrace what I had to do to get it to work. The Thonny package manager let me down; says it updated py5 when it didn’t really. Latest py5 version is here if you don’t already know: Release Important Bug Fix · py5coding/py5generator · GitHub
See my second post for what I think is a solid theory. I can easily edit the py5.core.Sketch.setup file but am hung up on how to recompile it so I can test it.
Here’s some pretty good evidence that my theory is correct. Try swapping the last two import calls and see the difference. On MacOS the following code generates the same error message that was observed on Windows 11. The title isn’t set and draw() becomes non-functional.
Error: ClassCastException: class processing.javafx.PSurfaceFX$ResizableCanvas cannot be cast to class java.awt.Canvas (processing.javafx.PSurfaceFX$ResizableCanvas is in unnamed module of loader 'app'; java.awt.Canvas is in module java.desktop of loader 'bootstrap')
However - note that I’ve never actually run the build on Windows, so there might be platform specific problems in the build process. I do all development on Linux and MacOS. I will test on all platforms but writing code on Windows is not for me.
If you have Windows and would like to try Linux, I would recommend giving the Windows Subsystem a try. You can have Linux run alongside Windows and work in a terminal.
But for programming, you should use whatever works best for you! I use Linux and MacOS because that is what works best for me. I don’t want to imply there is some kind of objective reality where Linux is better than other options or that Linux is the best choice for everyone. Find where you are comfortable programming and use that.
You should consider a distro which is lightweight (like the XFCE desktop environment), never needs to be upgraded (rolling-release model) and has everything setup & ready to use.
For all of those criteria, I know these 2 Linux distros:
Garuda Linux XFCE:
Manjaro XFCE:
You should be able to virtualize any of those distros w/ good performance.
XFCE is a nice, lightweight, and accessible desktop environment. It’s a good choice.
I have done some investigation of this problem and I see that although the code change is simple, getting it to compile will require some upgrades/improvements to the build process that I was going to do eventually anyway. Give me some time to work on this first.
Finally got javafx in py5 to run in Windows 11. It turned out to be difficult to get p5 to recognize javafx when editing the Sketch file. However, the block of code that was causing the error just setFocus which is not really necessary anyway, so I REMmed out all of this code and recompiled the py5.jar and it worked. No more error, the output is good and so far see no ill-effects from deleting that code block. Output: