Exception when calling series.setCandleColor()

tystr

Member
Joined
May 1, 2021
Posts
7
Likes
1
I'm attempting to color certain candles in a study. When I call

Java:
@Override
protected void calculate(int index, DataContext ctx)
{
    DataSeries series = ctx.getDataSeries();
    
    // ...
    
    series.setPriceBarColor(index, Color.GREEN);

        
    // ...

}

the application starts lagging hard, and in the application logs there is a flood of the following exception messages:

Code:
java.lang.Exception
    at com.motivewave.common.i.c(Util.java:2460)
    at com.motivewave.common.ui.util.FXGraphics2D.setColor(FXGraphics2D.java:240)
    at com.motivewave.platform.ui.draw.component.graph.ab.c(PriceBar.java:156)
    at com.motivewave.platform.ui.draw.aa.a(Drawable.java:92)
    at com.motivewave.platform.ui.draw.Graph.a(Graph.java:2041)
    at com.motivewave.platform.ui.draw.Graph.j(Graph.java:1530)
    at com.motivewave.platform.ui.draw.Graph.d(Graph.java:1217)
    at com.motivewave.platform.ui.draw.Graph.a(Graph.java:1382)
    at com.motivewave.platform.ui.draw.p.c(DAPane.java:153)
    at com.motivewave.platform.ui.draw.p.f(DAPane.java:137)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:447)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:446)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
java.lang.Exception
    at com.motivewave.common.i.c(Util.java:2460)
    at com.motivewave.common.ui.util.FXGraphics2D.setColor(FXGraphics2D.java:240)
    at com.motivewave.platform.ui.draw.component.graph.ab.c(PriceBar.java:282)
    at com.motivewave.platform.ui.draw.aa.a(Drawable.java:92)
    at com.motivewave.platform.ui.draw.Graph.a(Graph.java:2041)
    at com.motivewave.platform.ui.draw.Graph.j(Graph.java:1530)
    at com.motivewave.platform.ui.draw.Graph.d(Graph.java:1217)
    at com.motivewave.platform.ui.draw.Graph.a(Graph.java:1382)
    at com.motivewave.platform.ui.draw.p.c(DAPane.java:153)
    at com.motivewave.platform.ui.draw.p.f(DAPane.java:137)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:447)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:446)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)

as well as some longer traces:

Code:
java.lang.Exception
    at com.motivewave.common.i.c(Util.java:2460)
    at com.motivewave.common.ui.util.FXGraphics2D.setColor(FXGraphics2D.java:240)
    at com.motivewave.platform.ui.draw.component.graph.ab.c(PriceBar.java:282)
    at com.motivewave.platform.ui.draw.aa.a(Drawable.java:92)
    at com.motivewave.platform.ui.draw.Graph.a(Graph.java:2041)
    at com.motivewave.platform.ui.draw.Graph.j(Graph.java:1530)
    at com.motivewave.platform.ui.draw.Graph.d(Graph.java:1217)
    at com.motivewave.platform.ui.draw.Graph.a(Graph.java:1382)
    at com.motivewave.platform.ui.draw.p.c(DAPane.java:153)
    at com.motivewave.platform.ui.draw.p.a(DAPane.java:127)
    at com.motivewave.platform.ui.draw.r.resize(DAPane.java:302)
    at javafx.graphics/javafx.scene.Node.autosize(Node.java:3179)
    at javafx.graphics/javafx.scene.Parent.layoutChildren(Parent.java:1238)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1207)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Scene.doLayoutPass(Scene.java:576)
    at javafx.graphics/javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2476)
    at javafx.graphics/com.sun.javafx.tk.Toolkit.lambda$runPulse$2(Toolkit.java:413)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:412)
    at javafx.graphics/com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:439)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:563)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:543)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:536)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(QuantumToolkit.java:342)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
java.lang.Exception
    at com.motivewave.common.i.c(Util.java:2460)
    at com.motivewave.common.ui.util.FXGraphics2D.setColor(FXGraphics2D.java:240)
    at java.desktop/java.awt.Graphics2D.draw3DRect(Graphics2D.java:452)
    at com.motivewave.platform.ui.draw.component.graph.ab.c(PriceBar.java:283)
    at com.motivewave.platform.ui.draw.aa.a(Drawable.java:92)
    at com.motivewave.platform.ui.draw.Graph.a(Graph.java:2041)
    at com.motivewave.platform.ui.draw.Graph.j(Graph.java:1530)
    at com.motivewave.platform.ui.draw.Graph.d(Graph.java:1217)
    at com.motivewave.platform.ui.draw.Graph.a(Graph.java:1382)
    at com.motivewave.platform.ui.draw.p.c(DAPane.java:153)
    at com.motivewave.platform.ui.draw.p.a(DAPane.java:127)
    at com.motivewave.platform.ui.draw.r.resize(DAPane.java:302)
    at javafx.graphics/javafx.scene.Node.autosize(Node.java:3179)
    at javafx.graphics/javafx.scene.Parent.layoutChildren(Parent.java:1238)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1207)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Scene.doLayoutPass(Scene.java:576)
    at javafx.graphics/javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2476)
    at javafx.graphics/com.sun.javafx.tk.Toolkit.lambda$runPulse$2(Toolkit.java:413)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:412)
    at javafx.graphics/com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:439)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:563)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:543)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:536)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(QuantumToolkit.java:342)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)

What could be going on here? Am I missing something in how to color price bars? Is this a bug in the MotiveWave code?
 

Spin

Well-known member
Joined
May 22, 2019
Posts
480
Likes
192
Hmmm, let's see if we can debug this :)
Did you define the color GREEN like my snippet below, or are you using the 'standard' green ?

Java:
public static final Color GREEN = new Color(0,128,0);

What are the lines immediately above ? An 'if'-statement, I presume ?
 

tystr

Member
Joined
May 1, 2021
Posts
7
Likes
1
Thanks for the reply @Spin

What are the lines immediately above ? An 'if'-statement, I presume ?
While troubleshooting, I removed everything

Did you define the color GREEN like my snippet below, or are you using the 'standard' green ?
I wasn't defining the colors - I was simply trying to use the colors defined in java.awt.Color

I did try defining a color on the study class like
Java:
public static final Color testColor = new Color(0,0,255);
But using that resulted in the same behavior

HOWEVER

I have discovered that using the Defaults interface implementation to get the colors does NOT cause the issue, e.g.:
Java:
defaults.getBlueLine()

Seems my shortcut of trying to hardcode the color during dev instead of pulling it from the settings was causing the issue hah.


FWIW, this throws those exceptions:
Java:
new PathDescriptor("MyPath", "My Path", java.awt.Color.BLUE, 1.0f, null, true, true, true);
while this does not:
Java:
new PathDescriptor("MyPath", "My Path", defaults.getBlueLine(), 1.0f, null, true, true, true);


Really curious what the Defaults implementation is doing under the hood that causes this to work properly...
 

danielputra

Active member
Joined
Jul 22, 2021
Posts
29
Likes
53
MotiveWave is using java.awt.Color and javafx.scene.paint.Color, both share the same interface java.awt.Paint but there are implementation differences which seem not to be considered in all places in the MotiveWave code base. ColorInfo has a method getColorFX() which must be used in some context otherwise it would not be there.

Yet, there must be some kind of auto-correction happening as if you change the color to another one, click Apply and then change it back to the one you had and click again Apply, the problem is gone. The problem also disappears after a restart of MotiveWave.

I hope this helps at least a bit.
 
Top