You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure if the return value would be use anyway as i don't see when the IsEngineValid could fail, i suppose openttd won't offer a preview to someone if the engine is not valid...
Kinda seems like a notreach() state, even wonder why the IsEngineValid check exist then.
But if the IsEngineValid check have a real reason, on failure in all the functions it should return a more consistant error : -1 for everyone or VT_INVALID, but not a mix like it is.
IsEngineValid is there for the case the player messes things up with (changing) NewGRFs. So, it's unlikely to happen but could and in that case it's better to let the AI crash than to crash OpenTTD.
GetName returns a string, which means a pointer. Returning -1 as pointer will cause crashes when you do not check for that. NULL is the universal way for saying there is no string. As such, NULL is the expected value for a 'no string'.
GetCargoType returns a cargo type. CT_INVALID is a value for a bad cargo type. -1 is not, especially if you do a check for Cargo.IsValid(ct) or so, or compare to CT_INVALID but not to -1.
GetCapacity returns an amount, -1 (which is returns, not VT_INVALID) is a good value for bad data. VT_INVALID is definitely not a good value as 255 is a valid capacity.
Likewise for the three other functions.
If you look at the rest of the APIs, you'll find plenty of cases where the 'bad data' value isn't a default -1. In all cases the actually chosen canary value should be better than just -1.
krinn opened the ticket and wrote:
Reported version: trunk
Operating system: All
This issue was imported from FlySpray: https://bugs.openttd.org/task/5802
The text was updated successfully, but these errors were encountered: