0

Here's some Haxe, written as part of a game in HaxeFlixel.

var fx:Float = 236/43; //Some float
var ix:Int = cast(fx); //Cast to an int
someArray[v];          //Access an array

The array access causes a violation.

I can't think of a reason why this would happen, or even how it might. Is there anything I might not be thinking of?

mtrc
  • 1,317
  • 3
  • 16
  • 39
  • 1
    What is `f()`? It will be hard to help without seeing more code... – Jason O'Neil Jun 25 '14 at 02:39
  • f() didn't matter - I could replace it with any array access. I've diagnosed the problem now and will post an answer later. Short version: casting Float to Int in Haxe does not work like it does in other languages... (use Std.int()) – mtrc Jun 25 '14 at 11:51
  • 1
    Actually, I should tell you that casting Int to Float doesn't work in haxe at all and isn't allowed. What you walked into surely was platform-dependent thing(and you probably typed your f function wrong). (Btw, I should note that you didn't post whole context to solve your problem, actually.) Also, please, answer to your question and accept this answer please, so the question won't hang out in "unanswered". – stroncium Jun 25 '14 at 12:36
  • Yep, I will do that. I thought there was a time limit for accepting one's own answer but I guess that's up. Thanks for the feedback. I'll edit the question too. – mtrc Jun 25 '14 at 16:36

1 Answers1

3

Casting a Float to an Int is a big no-no in Haxe. Using Std.int() to convert the Float was what I needed to do.

mtrc
  • 1,317
  • 3
  • 16
  • 39