Opened 12 years ago

Closed 11 years ago

#1528 closed defect (wontfix)

[PATCH] Implicit js->C++ type conversions are non-fatal

Reported by: Deiz Owned by: Deiz
Priority: If Time Permits Milestone:
Component: Core engine Keywords: patch
Cc: Patch:

Description

Because js->C++ value conversion errors are non-fatal, Engine.SetSimRate() will attempt to set the sim rate to NaN if you pass it something that isn't a float.

This also includes no-argument cases, i.e. a literal "Engine.SetSimRate()", causing 0 A.D. to hang indefinitely. I've managed to fat-finger that particular line twice.

Trivial patch just checks using the isnan macro and prints an error if so.

Attachments (2)

simrate.patch (510 bytes ) - added by Deiz 12 years ago.
implicit-conversion.patch (2.6 KB ) - added by Deiz 12 years ago.

Download all attachments as: .zip

Change History (6)

by Deiz, 12 years ago

Attachment: simrate.patch added

comment:1 by historic_bruno, 12 years ago

Keywords: review removed

Discussed in IRC, would prefer a more general solution to the problem of failed JS argument conversions (they shouldn't continue to call the C++ function). Also there are a number of other cases were bad console input can crash the game and/or have nasty side effects.

comment:2 by Deiz, 12 years ago

Keywords: review added
Summary: [PATCH] Engine.SetSimRate() doesn't handle NaN.[PATCH] Implicit js->C++ type conversions are non-fatal

Updated per the last comment and some further discussion.

I've added an ERROR_IF_NOT macro, which largely takes the place of WARN_IF_NOT (which is still used for two types which implement their own failure cases).

Existing warnings were extremely loud; implicit conversions only result due to script bugs. It seems vastly preferable to throw an error than to run engine functions with the implicitly-converted values (often NaN in the case of numbers).

by Deiz, 12 years ago

Attachment: implicit-conversion.patch added

comment:3 by historic_bruno, 12 years ago

Relevant IRC log: 2012-07-15 around 02:25

Philip's argument against this: 2012-07-17 around 21:09

comment:4 by historic_bruno, 11 years ago

Keywords: review removed
Milestone: Backlog
Resolution: wontfix
Status: newclosed

Closing as wontfix, the reason being this isn't really a problem with type conversion (it works fine if code is written properly), but a problem with the interface we provide for user config via console. I think it could be addressed better as part of #1810. E.g. Engine.SetSimRate() should probably go away and be replaced with something better.

Note: See TracTickets for help on using tickets.