🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Nested conditional expressions with concatenated strings - crash

Started by
2 comments, last by WitchLord 10 years, 10 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.

Advertisement

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

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