Results 1 to 13 of 13

Thread: Distance returning "Invalid floating point operation at line"

  1. #1
    Join Date
    Dec 2013
    Location
    Sweden
    Posts
    269
    Mentioned
    17 Post(s)
    Quoted
    161 Post(s)

    Default Distance returning "Invalid floating point operation at line"

    Encountering this error sometimes with my PC-script, it happens sporadically (thanks @Turpinator), and I can't explain why, any ideas? http://pastebin.com/FFFsmu38. Walker is a global var for RSWalker. Self.Tile is a static variable for the tile of the portal.
    "Once you begin to think, you can't stop."

    Life > 0

  2. #2
    Join Date
    Dec 2007
    Posts
    289
    Mentioned
    4 Post(s)
    Quoted
    86 Post(s)

    Default

    I encounter seemingly random "Invalid floating point operation at line" errors when using the Round function. (in your code round is used in the Distance function)

    It's pretty tough to troubleshoot and find a cause. Yet another Simba bug :P

    The only thing I can think of is that you may wish to sanitise Walker._GetPos.X/Walker._GetPos.Y in case they're too large.

  3. #3
    Join Date
    Oct 2006
    Posts
    6,752
    Mentioned
    95 Post(s)
    Quoted
    532 Post(s)

    Default

    @kristi; Yeah, it's what @honeyhoney; said most likely. I had this happen a lot when I was working on my PC-script as well. What caused it for me, is when the game would end, the tiles/location gathered from reflection would be garbage, as you're in the middle of teleporting. This caused the values calculated in the Distance method to error out. I just added a check to see how large the tile values are. Unless RS-Walker doesn't work like that, I don't know as I haven't ever looked at it.
    “The long-lived and those who will die soonest lose the same thing. The present is all that they can give up, since that is all you have, and what you do not have, you cannot lose.” - Marcus Aurelius

  4. #4
    Join Date
    Mar 2013
    Posts
    1,010
    Mentioned
    35 Post(s)
    Quoted
    620 Post(s)

    Default

    Don't use _GetPos use GetMyPos and if that doesn't work try disabling memory scanning
    #slack4admin2016
    <slacky> I will build a wall
    <slacky> I will ban reflection and OGL hooking until we know what the hell is going on

  5. #5
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    @kristi; First off: Don't use ._GetPos directly (I don't get why people do this, there is a reason for the prefixing underscore). Also it's really wasting resources and time to compute the position _FOUR_ times in a row, the way you do.
    Computing your position is by no means a cheap operation.

    ----

    `Distance(..)` will fail given a (somewhat) large "delta" (x1-x2, y1-y2) as it will compute the square of those, and add together the squares. As the input to `Sqr` is `Int32` the output from is also `Int32`, so it overflows.
    The error then comes from the call to `Sqrt`, again because the input argument wrapped around to a negative number; Delta's greater than 32767 can cause that to happen.
    The "Sqrt"-function isn't capable of handling negative numbers (the square root of a negative number is a complex number). Hence the error.


    One solution is as follows:
    Simba Code:
    function TPortal.GetDist(): Int32;
    var pos:TPoint;
    begin
      pos := Walker.GetMyPos();
      if (pos.X < 1) or (pos.Y < 1) then
        Exit;
     
      Result := Round( Hypot(pos.X - Self.Tile.X, pos.Y - Self.Tile.Y) );
    end;
    This works because Hypot takes a float, so it wont overflow like Distance which works on Int32.
    Sidenote: Not sure why you call it a "tile", RSWalker doesn't work with "tiles", it returns the pixel you are located on in the given world map.


    It's a mystery to me how you get that large numbers from RSWalker tho. It should always give values within the range of the given image. But idk been a while since I've worked on it.


    Quote Originally Posted by honeyhoney View Post
    I encounter seemingly random "Invalid floating point operation at line" errors when using the Round function. (in your code round is used in the Distance function)
    ... Yet another Simba bug :P
    That would happen if you input an invalid number (in this case a negative number is passed to Sqrt, due to an overflow). I would hesitate to call it a Simba bug, but rather a limitation due to the datatype used, we can however compute distance purely in Lape as `Sqr` will return `Int64`, unlike in Free pascal, where it returns `Int32` when given `Int32` input.
    Last edited by slacky; 04-29-2016 at 07:27 AM.
    !No priv. messages please

  6. #6
    Join Date
    Dec 2013
    Location
    Sweden
    Posts
    269
    Mentioned
    17 Post(s)
    Quoted
    161 Post(s)

    Default

    Quote Originally Posted by slacky View Post
    @kristi; First off: Don't use ._GetPos directly (I don't get why people do this, there is a reason for the prefixing underscore). Also it's really wasting resources and time to compute the position _FOUR_ times in a row, the way you do.
    Computing your position is by no means a cheap operation.

    ----

    `Distance(..)` will fail given a (somewhat) large "delta" (x1-x2, y1-y2) as it will compute the square of those, and add together the squares. As the input to `Sqr` is `Int32` the output from is also `Int32`, so it overflows.
    The error then comes from the call to `Sqrt`, again because the input argument wrapped around to a negative number; Delta's greater than 32767 can cause that to happen.
    The "Sqrt"-function isn't capable of handling negative numbers (the square root of a negative number is a complex number). Hence the error.


    One solution is as follows:
    Simba Code:
    function TPortal.GetDist(): Int32;
    var pos:TPoint;
    begin
      pos := Walker.GetMyPos();
      if (pos.X < 1) or (pos.Y < 1) then
        Exit;
     
      Result := Round( Hypot(pos.X - Self.Tile.X, pos.Y - Self.Tile.Y) );
    end;
    This works because Hypot takes a float, so it wont overflow like Distance which works on Int32.
    Sidenote: Not sure why you call it a "tile", RSWalker doesn't work with "tiles", it returns the pixel you are located on in the given world map.


    It's a mystery to me how you get that large numbers from RSWalker tho. It should always give values within the range of the given image. But idk been a while since I've worked on it.



    That would happen if you input an invalid number (in this case a negative number is passed to Sqrt, due to an overflow). I would hesitate to call it a Simba bug, but rather a limitation due to the datatype used, we can however compute distance purely in Lape as `Sqr` will return `Int64`, unlike in Free pascal, where it returns `Int32` when given `Int32` input.
    Ah, some of those things had I completely overlooked. Thanks Slack
    "Once you begin to think, you can't stop."

    Life > 0

  7. #7
    Join Date
    Dec 2013
    Location
    Sweden
    Posts
    269
    Mentioned
    17 Post(s)
    Quoted
    161 Post(s)

    Default

    @slacky; any idea why this returns Acess Violation? It might be something else in the script but line 9 is what gets highlighted.
    Simba Code:
    1. function TPortal.GetDist(): Int32;
    2. var
    3.   pos : TPoint;
    4.   tmp : Int32;
    5. begin
    6.   pos := Walker.GetMyPos();
    7.   if (pos.X < 1) or (pos.Y < 1) or (Pos.X > 10000) or (Pos.Y > 10000) then
    8.     Exit;
    9.   tmp := Round(Hypot(pos.X - Self.Tile.X, pos.Y - Self.Tile.Y));
    10.   Result := tmp;
    11. end;
    "Once you begin to think, you can't stop."

    Life > 0

  8. #8
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by kristi View Post
    @slacky; any idea why this returns Acess Violation? It might be something else in the script but line 9 is what gets highlighted.
    Simba Code:
    1. function TPortal.GetDist(): Int32;
    2. var
    3.   pos : TPoint;
    4.   tmp : Int32;
    5. begin
    6.   pos := Walker.GetMyPos();
    7.   if (pos.X < 1) or (pos.Y < 1) or (Pos.X > 10000) or (Pos.Y > 10000) then
    8.     Exit;
    9.   tmp := Round(Hypot(pos.X - Self.Tile.X, pos.Y - Self.Tile.Y));
    10.   Result := tmp;
    11. end;
    Is TPortal.Tile a method or a field? if it's returning a point that is probably were you are getting your access violation.

  9. #9
    Join Date
    Dec 2013
    Location
    Sweden
    Posts
    269
    Mentioned
    17 Post(s)
    Quoted
    161 Post(s)

    Default

    Quote Originally Posted by rj View Post
    Is TPortal.Tile a method or a field? if it's returning a point that is probably were you are getting your access violation.
    That would've been my guess too, however it's just a field.
    "Once you begin to think, you can't stop."

    Life > 0

  10. #10
    Join Date
    Jun 2012
    Posts
    586
    Mentioned
    112 Post(s)
    Quoted
    296 Post(s)

    Default

    Could do like @Clarity; and anytime you run into a random Access Violation bug just throw it into a try except end;. :-P




    Skype: obscuritySRL@outlook.com

  11. #11
    Join Date
    Jun 2013
    Location
    Scranton
    Posts
    496
    Mentioned
    5 Post(s)
    Quoted
    220 Post(s)

    Default

    Offtopic but humanMMouse has been giving me invalid floating point errors in one of my scripts for some reason. And it only has started to happen recently (haven't touched this script at all).

  12. #12
    Join Date
    Dec 2013
    Location
    Sweden
    Posts
    269
    Mentioned
    17 Post(s)
    Quoted
    161 Post(s)

    Default

    Quote Originally Posted by Obscurity View Post
    Could do like @Clarity; and anytime you run into a random Access Violation bug just throw it into a try except end;. :-P
    Haha never thought of that, lazy solution but it works for now

    Quote Originally Posted by jstemper View Post
    Offtopic but humanMMouse has been giving me invalid floating point errors in one of my scripts for some reason. And it only has started to happen recently (haven't touched this script at all).
    That's weird, maybe try re-installing the include (assuming you use Aerolib), might have touched that code somewhere that messes it up.
    "Once you begin to think, you can't stop."

    Life > 0

  13. #13
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Quote Originally Posted by kristi View Post
    @slacky; any idea why this returns Acess Violation? It might be something else in the script but line 9 is what gets highlighted.
    Simba Code:
    1. function TPortal.GetDist(): Int32;
    2. var
    3.   pos : TPoint;
    4.   tmp : Int32;
    5. begin
    6.   pos := Walker.GetMyPos();
    7.   if (pos.X < 1) or (pos.Y < 1) or (Pos.X > 10000) or (Pos.Y > 10000) then
    8.     Exit;
    9.   tmp := Round(Hypot(pos.X - Self.Tile.X, pos.Y - Self.Tile.Y));
    10.   Result := tmp;
    11. end;
    That seems very weird. Are you sure self is actually passed along? Aka calling the method with a VARIABLE, not a constant or just the type (as a static method)?
    Last edited by slacky; 07-09-2017 at 04:36 PM.
    !No priv. messages please

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •