ArticySoftware / Articy3ImporterForUnreal

Articy Importer plugin for the Unreal Engine 4 and Unreal Engine 5 (work in progress).
MIT License
98 stars 41 forks source link

Incorrect result when comparing floats and ints in Expresso script #27

Closed Liosan closed 4 years ago

Liosan commented 4 years ago

Hello :) We are running Articy with Unreal, using this plugin, and we have run into an issue that seems rather... disturbing.

Consider the following Expresso condition: getProp(getObj("Player"), "PlayerProperties.Intimidation") < 3

PlayerProperties.Intimidation is a float, and is compared against an integer value. I would expect the condition to evaluate to true if the float value is larger than 3.0, and false otherwise. The result, however, is undefined behaviour.

After debugging, I managed to track down the issue. The generated C++ looks like this:

return ConditionOrTrue(
    getProp(getObj("Player"), "PlayerProperties.Intimidation") < 3
)

This causes an implicit cast - the value 3 is cast to ExpressoType with type set to Int. Then, ExpressoType::operator< is evaluated; however, this operator assumes that both expressions are of the same type; it just performs GetFloat() < Other.GetFloat(). However, in this case Other is an Int; so we are reading undefined values from a union.

herr-edgy commented 4 years ago

Thanks for notifying us. While this "same-type" assumption is made throughout the Unreal expresso script system, we will include a fix for the most common comparison operators regarding the float and int mismatch, including <, >, >=, <=, == and !=, in the next release.