Jump to content
  • Advertisement
Sign in to follow this  
RCL

switch...case bug

This topic is 5100 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi There seems to be a bug in AngelScript. Here is the code that reproduces it: ===== 8< ===== int main() { int i; for ( i = 0; i <= 5; i ++ ) { switch ( i ) { case 5: Log( "5" ); break; case 4: Log( "4" ); break; case 3: Log( "3" ); break; case 2: Log( "2" ); break; case 1: Log( "1" ); break; default: Log( "default" ); break; } } return 0; } ===== >8 ===== The output is: ===== 8< ===== default default default default 4 default ===== >8 ===== 'Works' with AngelScript 1.9.0. If cases are sorted ascending, everything is Ok. Cheers, RCL

Share this post


Link to post
Share on other sites
Advertisement
Thanks, for the detailed report. I'll check it out. If the fix is simple I'll tell you here, otherwise I'll release an update soon.

Share this post


Link to post
Share on other sites
I feel really silly now. It turns out that I can't even write a simple bubble sort [wink].

The fix for this bug is to replace the loop in as_compiler.as line 691 with the following:


for( int fwd = 1; fwd < caseValues.GetLength(); fwd++ )
{
for( int bck = fwd - 1; bck >= 0; bck-- )
{
int bckp = bck + 1;
if( caseValues[bck] > caseValues[bckp] )
{
// Swap the values in both arrays
int swap = caseValues[bckp];
caseValues[bckp] = caseValues[bck];
caseValues[bck] = swap;

swap = caseLabels[bckp];
caseLabels[bckp] = caseLabels[bck];
caseLabels[bck] = swap;
}
else
break;
}
}


Share this post


Link to post
Share on other sites
Quote:
Original post by WitchLord
I feel really silly now. It turns out that I can't even write a simple bubble sort [wink].


Nobody is guaranteed from mistakes :-)

Thanks, it works now.

Cheers,
RCL

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!