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

SFX-8: `ColorfulCircles` and `SimpleColorfulCircles` demos fail #69

Closed
jpsacha opened this Issue May 24, 2014 · 6 comments

Comments

Projects
None yet
1 participant
@jpsacha
Member

jpsacha commented May 24, 2014

From jpsacha on July 30, 2013 22:49:44

scalafx.ColorfulCircles and SimpleColorfulCircles fail with StackOverflowError in ScalaFX 8. Tested with Java 8 ea b100.

Part of the error message and stack trace is below (full message and trace are very long):

com.sun.javafx.binding.SelectBinding$SelectBindingHelper getObservableValue
WARNING: Exception while evaluating select-binding [width]
com.sun.javafx.binding.SelectBinding$SelectBindingHelper getObservableValue
WARNING: Exception while evaluating select-binding [width]
com.sun.javafx.binding.SelectBinding$SelectBindingHelper getObservableValue
WARNING: Exception while evaluating select-binding [width]
...
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:867)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:56)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:158)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.StackOverflowError
at com.sun.javafx.binding.SelectBinding$SelectBindingHelper.getObservableValue(SelectBinding.java:481)
at com.sun.javafx.binding.SelectBinding$AsDouble.computeValue(SelectBinding.java:190)
at javafx.beans.binding.DoubleBinding.get(DoubleBinding.java:203)
at javafx.beans.property.DoublePropertyBase.get(DoublePropertyBase.java:133)
at javafx.scene.shape.Rectangle.getWidth(Rectangle.java:235)
at javafx.scene.shape.Rectangle.toString(Rectangle.java:564)
at java.lang.String.valueOf(String.java:2985)
at java.lang.StringBuilder.append(StringBuilder.java:131)
at javafx.beans.property.ReadOnlyObjectProperty.toString(ReadOnlyObjectProperty.java:69)
at java.lang.String.valueOf(String.java:2985)
at java.lang.StringBuilder.append(StringBuilder.java:131)
at com.sun.javafx.binding.SelectBinding$SelectBindingHelper.getObservableValue(SelectBinding.java:501)
at com.sun.javafx.binding.SelectBinding$AsDouble.computeValue(SelectBinding.java:190)
at javafx.beans.binding.DoubleBinding.get(DoubleBinding.java:203)
at javafx.beans.property.DoublePropertyBase.get(DoublePropertyBase.java:133)
at javafx.scene.shape.Rectangle.getWidth(Rectangle.java:235)
at javafx.scene.shape.Rectangle.toString(Rectangle.java:564)
at java.lang.String.valueOf(String.java:2985)
at java.lang.StringBuilder.append(StringBuilder.java:131)
at javafx.beans.property.ReadOnlyObjectProperty.toString(ReadOnlyObjectProperty.java:69)
at java.lang.String.valueOf(String.java:2985)
at java.lang.StringBuilder.append(StringBuilder.java:131)
...

Original issue: http://code.google.com/p/scalafx/issues/detail?id=69

@jpsacha

This comment has been minimized.

Member

jpsacha commented May 24, 2014

From mike@hindsight-consulting.com on July 31, 2013 14:37:19

This same problem also affects the SimpleColorfulCircles demo.

In both demos, the stage is initialized to be an 800x600 rectangle. Within the scene definition, both demos also then create one or more Rectangles using their Scene's dimensions, with statements such as:

width <== scene.width
height <== scene.height

Since these statements are used within the Scene's definition, I think its possible that the scene has yet to be constructed and, hence, has no values for these fields. In turn, this causes JavaFX to recursively search for the value until the stack exception occurs.

In any case, the bug can be resolved by storing the stage width and height as regular vals, then initializing the corresponding fields to those values, as in the attached versions of the demo sources.

Attachment: ColorfulCircles.scala SimpleColorfulCircles.scala

@jpsacha

This comment has been minimized.

Member

jpsacha commented May 24, 2014

From jpsacha on August 01, 2013 19:45:11

Summary: scalafx.ColorfulCircles demo fails in SFX-8 (was: scalafx.ColorfulCircles demo to fails in SFX-8)
Labels: SFX-8

@jpsacha

This comment has been minimized.

Member

jpsacha commented May 24, 2014

From jpsacha on August 26, 2013 19:05:10

Owner: ---

@jpsacha

This comment has been minimized.

Member

jpsacha commented May 24, 2014

From jpsacha on August 31, 2013 07:53:06

Summary: SFX-8: ColorfulCircles and SimpleColorfulCircles demos fail (was: scalafx.ColorfulCircles demo fails in SFX-8)

MichaelJAllen added a commit to MichaelJAllen/scalafx that referenced this issue Jul 4, 2015

Fixed issue scalafx#69.
Both ColorfulCircles and SimpleColorfulCircles demos now work as they
should.

@jpsacha jpsacha modified the milestones: 8.0.*-R9, 8.0.*-R10 Sep 26, 2015

@jpsacha

This comment has been minimized.

Member

jpsacha commented Oct 19, 2015

Here is my understanding what is happening and and a suggested resolution. To focus on the key problem consider following simplified but complete code:

import scalafx.Includes._
import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.scene.Scene
import scalafx.scene.paint.Color
import scalafx.scene.shape.Rectangle

object Issue69Tester extends JFXApp {
  stage = new PrimaryStage {
    scene = new Scene {
      content = new Rectangle {
        width <== scene.width
        height <== scene.height
        fill = Color.Black
      }
    }
  }
}

Running this resulted in StackOverflowError in line width <== scene.width.

Pay attention to scene.width. Notice that scene is of type ReadOnlyObjectProperty[jfx.Scene]. It is a property of the stage. At the moment line width <== scene.width is executed, the scene property value has not yet boon assigned. There is a trick that supposed to allow it to work. Notice that since scene is a ReadOnlyObjectProperty it does not have method width. There is an implicit conversion applied that converts scene property to scalafx.scene.SceneProperty. The idea behind SceneProperty was to "...enables the reading of properties of the scene that will be set into the property later on". The implementation looks something like this:

class SceneProperty(override val delegate: jfxbp.ReadOnlyObjectProperty[jfxs.Scene]) extends ... {
...
  def width = jfxbb.Bindings.selectDouble(delegate, "width")
...
}

This somehow worked in JavaFX 2. Actual scene this supposed to be the value of the delegate property, but that value is not yet assigned. That call to selectDouble is not really legitimate, it is passing in an invalid argument that should have correct value only sometime later. While it somehow worked in JavaFX 2, in JavaFX 8 things changed and that call results in StackOverflowError. JavaFX 8 is trying to find a width property but its stating point is not yet a valid property.

I think that SceneProperty should be removed as its use leads to problems.

My fix for the code above would be to use direct reference to the constructed scene (a named this of a scene). I name the reference, as _scene, so it can be easily accessed from nested objects like Rectangle. Here is the corrected code

import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.scene.Scene
import scalafx.scene.paint.Color
import scalafx.scene.shape.Rectangle

object Issue69WorkaroundTester extends JFXApp {
  stage = new PrimaryStage {
    scene = new Scene { _scene =>
      content = new Rectangle {
        width <== _scene.width
        height <== _scene.height
        fill = Color.Black
      }
    }
  }
}

It looks quite similar to original.

By the way there is also scalafx.scene.control.TextFieldProperty that should be removed too, for the same reason as `SceneProperty.

@jpsacha jpsacha closed this Oct 19, 2015

@jpsacha

This comment has been minimized.

Member

jpsacha commented Oct 24, 2015

Looks that it was closed by mistake.

@jpsacha jpsacha reopened this Oct 24, 2015

jpsacha added a commit that referenced this issue Oct 27, 2015

@jpsacha jpsacha closed this Oct 27, 2015

jpsacha added a commit to scalafx/ProScalaFX that referenced this issue Oct 30, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment