Bug with particular inline if statement

Started by
4 comments, last by Thy Reaper 14 years, 2 months ago
I just found a strange bug with a particular arrangement of operations and an inline if:
void advance(bool full) {
    nextThink = gameTime + ( (full ? 10.0 : 1.0) * 30.0 );
}
Expected: nextThink = 300 or 30, depending on the argument. Result: 900. (tested with different values, always the square of the last value) The function is a method in a class. nextThink is a member of that class. gameTime is a global property accessor. Removing this operation eliminates the bug. Similarly:
void advance(bool full) {
    nextThink = gameTime + ( 30.0 * (full ? 10.0 : 1.0) );
}
Expected: nextThink = 300 or 30, depending on the argument. Result: 100 (full was true in this case, so it used the result of the inline if twice)
Advertisement
POST DELETED BY THE USER!
Looks like a bug in the compiler. It is probably overwriting a temporary variable too soon.

I'll have this fixed as soon as possible. In the meantime I suggest you break up this expression in multiple statements, which should work around the bug.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I've reproduced the problem. For some reason it only happens when using double types. If you use float, the expression works correctly.

I'll have a solution soon.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I've checked in the fix in the SVN now (rev 555).

Diff for as_compiler.cpp.

Thanks for reporting this.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thank you.

This topic is closed to new replies.

Advertisement