Slapstick
Mar 2 2012, 11:15
I just stumbled across this bug and since it seems that it likely affects a huge part of the Java API I thought I would post it in a separate thread to get more attention.
Short story
I've been attempting to attach a flashing light to a police car and the following code will cause a CTD.
// Assume we have a GameObject named "light"
RVEngine.setLightColor(light, Array.asList(0.3, 0.0, 0.0));
But the following code works perfectly
RVEngine.setLightColor(light, Array.asList(0.3f, 0.0f, 0.0f));
Long Story
The setLightColor function expects a GameObject and a list of "floats" as parameters. However, the Java default is to represent floating point numbers as "doubles". So the first example attempts to call RVEngine.setLightColor with a list of doubles, which causes a CTD.
In the second example I explicitly tell the compiler that the numbers are floats and the code works perfectly. I am just using setLightColor as an example here, but this bug seems to be pervasive.
Moral of the story
The TOH Java API is littered with List objects that don't specify what they are lists of. If you don't get the list element right it's back to the desktop for you.
Short story
I've been attempting to attach a flashing light to a police car and the following code will cause a CTD.
// Assume we have a GameObject named "light"
RVEngine.setLightColor(light, Array.asList(0.3, 0.0, 0.0));
But the following code works perfectly
RVEngine.setLightColor(light, Array.asList(0.3f, 0.0f, 0.0f));
Long Story
The setLightColor function expects a GameObject and a list of "floats" as parameters. However, the Java default is to represent floating point numbers as "doubles". So the first example attempts to call RVEngine.setLightColor with a list of doubles, which causes a CTD.
In the second example I explicitly tell the compiler that the numbers are floats and the code works perfectly. I am just using setLightColor as an example here, but this bug seems to be pervasive.
Moral of the story
The TOH Java API is littered with List objects that don't specify what they are lists of. If you don't get the list element right it's back to the desktop for you.