I’ve come across a very specific Maths bug which is only occuring on Windows targets. Here’s a verbal description, and example code - the maths in this example work fine for flash, html, neko. simplest form code below to demonstrate the error.
Verbally, a dynamic array, contains a two dimensional array of Floats, The error occurs when multiplying a float from the array with another number. in most cases the maths will be correct, however whenever the Float within the array is smaller in magnitude tham one, (i.e. between -1 and 1) , the result of the multiplication will incorrectly be given as 0 !
var a:Array<Float> = new Array();
a[0] = 0.5; // incorrect maths results when -1 < a[0] < 1
var b:Array<Array<Float>> = new Array();
b.push(a);
var c:Array<Dynamic> = new Array();
c.push(b);
var m:Float = 0.5; // any number
trace(c[0][0][0] + " * " + m + " = " + (c[0][0][0] * m));
the maths will then work in this simplified example … but the maths still fail when c is a dynamic array. (all this means is i’ve over simplified the problem when creating this example, my c array is a display list with various members, rather than c just being a 3 dimensional array)
Don’t use Dynamic When you use Dynamic the compiler can’t check types or apply optimizations, is error prone and the runtime behavior will be unspecified. http://haxe.org/manual/types-dynamic.html
You have a few options:
Hint the compiler what the expected type of the value will be.
Let the compiler infer the type.
Correctly type the variable with var c:Array<Array<Array<Float>>> ...