GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2009-07-05 10:03:40

flexaplex
Member
Registered: 2008-12-11
Posts: 72

many computational functions - large numbers give errors and crashes

Brief Description:            numbers above [tex]\approx 2^{62}[/tex] cause errors/crashes when used in many of the computational functions also erratic behaviour is exhibited in some at values of [tex]\approx 2^{32}[/tex]
GM Versions:                   GM7, #Partially Fixed In GM8: a string return value has been given for some functions others are still bugged
References:                     <none>
Example File:                   function error with large values.gmk
Bug Confirmed:               Yes
Hardware Dependent:     No

Main Info:

Yourself reported this bug; that the string() function caused an error and crashed the game when used upon a number above [tex]\approx 2^{62}[/tex], for example string(power(2,63)) will cause this bug. This is well within the precision limit so it should not be a problem for GM to handle. From subsequently testing I have seen that the bug varies the error and whether it crashes depending on the event you call it in.

- If you call the string function in a start event (creation, room start, room creation code, draw event) it causes an 'Unexpected Error Has Occurred' error.

- If you call the string in an alarm event (this seems to be a strange exception, no other events act the same from testing) it doesn't give an error message or crash the entire game however it does still crash the interpreter and no other code called after it in the alarm event is executed.

- If you call in any other event (key press, step, destroy, collision etc) then it does not give an error message but just crashes the entire game straight.

- If you call it in debug mode it is different again. It then causes a different error message 'Invalid floating point operation' and then crashes the entire game afterwards.

Further findings by xDanielx show that many of the computational functions such as abs(), max() etc behave in the same way not just string(). Some functions also have very erratic behaviour, for example floor() which exhibits the following behaviour:

[tex]\lfloor{10^{10}}\rfloor \Rightarrow 1410065408[/tex]
[tex]\lfloor{2^{32}}\rfloor \Rightarrow 0[/tex]
[tex]\lfloor{3^{32} - 10^{8}}\rfloor \Rightarrow -10^{8}[/tex]
[tex]\lfloor{2^{63}}\rfloor \Rightarrow error[/tex]

It seems that there's some 32-bit arithmetic involved, but I suspect figuring out the details would be more effort than it's worth.

Workaround:

This is not easy to workaround. You can try to look for other functions that are not bugged like string_format() which you can use instead of string. If that option is not available you will have to write your own script instead.

Last edited by flexaplex (2010-04-17 15:07:27)

Offline

#2 2009-07-05 13:54:03

xot
Administrator
Registered: 2007-08-18
Posts: 1,239

Re: many computational functions - large numbers give errors and crashes

Interesting variations in behaviour with this bug.

~2^62 is a little confusing since ~ and ^ are bitwise operators.

How about [tex]\approx 2^{62}[/tex]?


Abusing forum power since 1986.

Offline

#3 2009-07-05 14:34:27

flexaplex
Member
Registered: 2008-12-11
Posts: 72

Re: many computational functions - large numbers give errors and crashes

I forgot that you had math expressions. Not that you wouldn't realise they obviously weren't bitwise operators since -61 is not a large value.

Offline

#4 2009-07-05 19:28:36

xDanielx
Member
Registered: 2009-01-02
Posts: 38

Re: many computational functions - large numbers give errors and crashes

As I recall, it's not just string(...) that falters on inputs close to [tex]2^{64}[/tex] -- many of the computational functions do so, such as abs(...) and max(...). Some functions have really erratic behavior, e.g. floor:
[tex]\lfloor{10^{10}}\rfloor \Rightarrow 1410065408[/tex]
[tex]\lfloor{2^{32}}\rfloor \Rightarrow 0[/tex]
[tex]\lfloor{3^{32} - 10^8}\rfloor \Rightarrow -10^8[/tex]
[tex]\lfloor{2^{63}}\rfloor \Rightarrow error[/tex]
It seems that there's some 32-bit arithmetic involved, but I suspect figuring out the details would be more effort than it's worth.

Last edited by xDanielx (2009-07-05 19:31:09)

Offline

#5 2009-07-05 19:50:07

flexaplex
Member
Registered: 2008-12-11
Posts: 72

Re: many computational functions - large numbers give errors and crashes

xDanielx wrote:

As I recall, it's not just string(...) that falters on inputs close to [tex]2^{64}[/tex] -- many of the computational functions do so, such as abs(...) and max(...). Some functions have really erratic behavior, e.g. floor:
[tex]\lfloor{10^{10}}\rfloor \Rightarrow 1410065408[/tex]
[tex]\lfloor{2^{32}}\rfloor \Rightarrow 0[/tex]
[tex]\lfloor{3^{32} - 10^8}\rfloor \Rightarrow -10^8[/tex]
[tex]\lfloor{2^{63}}\rfloor \Rightarrow error[/tex]
It seems that there's some 32-bit arithmetic involved, but I suspect figuring out the details would be more effort than it's worth.

Good spot. Darn I can't change the topic title now.

I can't really be bothered working out the exact details either, I will report these further findings though.

Offline

#6 2009-07-05 21:34:09

xot
Administrator
Registered: 2007-08-18
Posts: 1,239

Re: many computational functions - large numbers give errors and crashes

You should be able to edit the topic title now.


Abusing forum power since 1986.

Offline

Board footer

Powered by FluxBB