December 27th: Trap

Arghhhhhhh, I just spent a couple of hours debugging the collision detection only to find out it was another obvious porting error! Even though they’re obvious, they can be super sneaky!

You see, switch statements are formatted differently between AS3 and Haxe. AS3 switch statements hew pretty closely to the C++ pattern, and look like this:

switch(value)
{
  case 1:
    doSomething();
    break;
  case 2:
  case 3:
    doSomethingElse(value);
    break;
  default:
    break;
}

In this example, case 2 and 3 have approximately the same effect, though they’d send different values to doSomethingElse(). However, Haxe does away with the ‘break’ statements, and rather than listing the cases for entry and having commands automatically fall-through if there’s no explicit break, you just list multiple values to enter the case and handle any fall-through situations manually. So:

switch(value)
{
  case 1:
    doSomething();
  case 2, 3:
    doSomethingElse(value);
  default:
}

All things considered, I rather like this change. It’s quite a bit more concise, and though fall-throughs were a useful tool they also could quickly become rather confusing. For the most part I’ve welcomed this change. HOWEVER, when porting code, it’s extremely easy to miss converting something like “case 2: case 3” into “case 2, 3”, and there are no immediate errors when it occurs. The code continues to compile just fine, but the code which previously executes under case 2 or 3 instead only executes for case 3, leaving case 2 completely empty.

Well. To make a long story as short as possible, this is what was broken in my collision detection. The code that was supposed to handle left-side and right-side collisions was only handling left-side collisions and completely ignoring all collisions from the right side. It has been fixed, and…

… now I’ve found a new error. Fuck.

Advertisements

About problemmachine

What is the nature of your problem? Can we modify the nature of your problem? Can your problem be touched? Eaten? May we eat your problem for you? May we eat your soul for you? Would you like a replacement problem? We make problems. We eat souls. We crap solutions. We are Problem Machine.
This entry was posted in Daily Update, Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s