Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


- - - - -

switch...case bug


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 RCL   Members   -  Reputation: 122

Like
0Likes
Like

Posted 03 September 2004 - 01:49 AM

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

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
0Likes
Like

Posted 03 September 2004 - 02:23 AM

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.


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

#3 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
0Likes
Like

Posted 03 September 2004 - 03:40 AM

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;
}
}



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

#4 RCL   Members   -  Reputation: 122

Like
0Likes
Like

Posted 03 September 2004 - 03:54 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS