openplanet-nl / issues

Issue tracker for Openplanet.
10 stars 0 forks source link

Text::ParseInt(64)/UInt(64)/Float/Double/HexColor(string s) all return 0 or garbage values when input string is invalid #431

Closed CodyNinja1 closed 6 months ago

CodyNinja1 commented 6 months ago

Example:

void Main()
{
    print(Text::ParseInt("hijklmno")); // returns 0, should instead raise an exception
    print(Text::ParseFloat("hijklmno")); // returns 0.0
    print(Text::ParseHexColor("hijklmno")); // returns vec4(1.32549, 1.21176, 1.47059, 1.60392)   
}

I personally think those functions should raise an error instead of returning unusable values.

ezio416 commented 6 months ago

For me, the last line returns vec4(1.07451, 1.20784, 1.34118, 1.47451) and it's the same on every game boot so maybe it has to do with what plugins, settings, username, etc. you have. In any case I agree these should raise exceptions

codecat commented 6 months ago

I fixed the call to Text::ParseHexColor so that it returns <0, 0, 0, 0> now.

Not sure if I like throwing exceptions for these, mostly as this would be a big behavioral change that might have some unexpected consequences.

I suppose you just want to check if the parsing worked? What about TryParseInt, TryParseFloat, TryParseHexColor functions?

CodyNinja1 commented 6 months ago

Sure! That could work for me and my use case, I just want a way to see if either parsing worked or if a string is able to be parsed (e.g. string.IsNumeric() or string.IsHex())