Advertisement

Nested conditional expressions with concatenated strings - crash

Started by September 01, 2013 05:51 PM
2 comments, last by WitchLord 11 years, 2 months ago

Hello!

Apologies if this has already been brought up somewhere, but I found a crash in the scriptstdstring addon when attempting to use a concatenated string as part of a nested conditional expression. I am using Angelscript for the AI in an RTS game, and I had this to let the script show a label for the units:


string s = "Status: " + 
(
(m_actionState == AS_MOVETO) ? "moving" :
(m_actionState == AS_FIRE_AT_POINT) ? "firing at point" :
(m_actionState == AS_FIRE_AT_UNIT) ? "firing at unit" :
"idle"
)
+ "\n";

... and that worked fine, so I am assuming the problem is not with the nesting of conditional expressions per se.

Next I wanted to show the current speed of movement, so I changed the "moving" part to a concatenated string like this:


string s = "Status: " + 
(
(m_actionState == AS_MOVETO) ? ("moving"+10) :
(m_actionState == AS_FIRE_AT_POINT) ? "firing at point" :
(m_actionState == AS_FIRE_AT_UNIT) ? "firing at unit" :
"idle"
)
+ "\n";

...and this caused a crash in the CopyConstructString function. It appears that the 'other' parameter being given to the function is not a string. Obviously the literal 10 is not the value I really want to use, but after some experimentation I narrowed the problem down to the presence of the concatenation operator. It also crashed with concatenation of two strings.

If the branch of the conditional with the concatenation was never used (eg. no units ever entered the AS_MOVETO state), the program would run ok but random garbage characters would show for the text, and a crash would subsequently occur when releasing the asIScriptEngine object.

This is trivial to work around and is not causing me any real problems, but it seems pretty odd so I thought I would report it anyway.

What version of AngelScript are you using? There was a bug fix related to the condition operator in the version 2.27.1.

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

Advertisement

argh... apologies again. I was using 2.26.3 and the problem does not occur with 2.27.1 - thanks for all your hard work!!

Thanks for the confirmation on the fix in the latest release. :)

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

This topic is closed to new replies.

Advertisement