HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.98k stars 439 forks source link

FlxControl fails on CPP for 1.09 #273

Closed bradparks closed 11 years ago

bradparks commented 11 years ago

Hey! I've got an old demo that uses FlxControl. It works for Flash, but not for CPP. Totally dies on CPP. No stack trace, no nothing, when I hit the left or right arrow keys.

Here's some sample code that causes the app to die when hitting left/right.

   if (FlxG.getPlugin(FlxControl) == null)
    {
      FlxG.addPlugin(new FlxControl());
    }

    //  Add this sprite to the FlxControl plugin and tell it we want the sprite to accelerate and decelerate smoothly
    FlxControl.create(this, FlxControlHandler.MOVEMENT_ACCELERATES, FlxControlHandler.STOPPING_DECELERATES, 1, true, false);

    //  Sprite will be controlled with the left and right cursor keys
    FlxControl.player1.setESDFControl(false, false, true, true);

    //  And SPACE BAR will make them jump up to a maximum of 200 pixels (per second), only when touching the FLOOR
    FlxControl.player1.setJumpButton("SPACE", FlxControlHandler.KEYMODE_PRESSED, 200, FlxObject.FLOOR, 250, 200);

    //  Because we are using the MOVEMENT_ACCELERATES type the first value is the acceleration speed of the sprite
    //  Think of it as the time it takes to reach maximum velocity. A value of 100 means it would take 1 second. A value of 400 means it w
    FlxControl.player1.setMovementSpeed(400, 0, 100, 200, 400, 0);

    //  Set a downward gravity of 400px/sec
    FlxControl.player1.setGravity(0, 400);

    FlxControl.player1.setSounds(jumpFX, null, walkFX);
Beeblerox commented 11 years ago

I found that this issue is connected with FlxObject's updateMotion() and will try to fix it ASAP

bradparks commented 11 years ago

hey! thanks for looking into this... i just tried this on my mac build (did a clean, then a build) and I still see the problem. Were the only changes the initial values for gravityX and gravityY?

private var gravityX:Int = 0; private var gravityY:Int = 0;

Beeblerox commented 11 years ago

@bradparks yes. I've changed only these 2 lines, sorry for this messed commit. It is strange, since i don't have such ptoblem on windows. But could you try to compile your project to neko target - it will give little more info about problem - and i'd like to see what it will tell you

sergey-miryanov commented 11 years ago

Did you try to run with -debug flag? Nme test cpp -debug

For me it produced stack traces for cpp target. 24.03.2013 11:31 пользователь "Zaphod" notifications@github.com написал:

@bradparks https://github.com/bradparks yes. I've changed only these 2 lines. It is strange, since i don't have such ptoblem on windows. But could you try to compile your project to neko target - it will give little more info about problem - and i'd like to see what it will tell you

— Reply to this email directly or view it on GitHubhttps://github.com/Beeblerox/HaxeFlixel/issues/273#issuecomment-15351806 .

bradparks commented 11 years ago

the problem is that it completely locks up and basically takes down my mac if I leave it running.... for both neko and CPP targets... I've tried cleaning, and using -debug as well, with no extra info being provided that I can see (at least in the console). So zero stack trace, just it locks up and that's it. Only when I press the left or right arrow keys. I haven't been able to find a great debugging solution on the mac yet.... i'm starting to use hxcpp's built in debugging, and hopefully that will reveal what's up.... for the time being, I'd just stopped using FlxControl, and did my own simpler control approach using stuff like so:

  this.acceleration.x = 0;
  if(FlxG.keys.LEFT)
  {
    this.facing = FlxObject.LEFT;
    this.acceleration.x -= this.drag.x;
  }
  else if(FlxG.keys.RIGHT)
  {
    this.facing = FlxObject.RIGHT;
    this.acceleration.x += this.drag.x;
  }

and it works totally fine....

Beeblerox commented 11 years ago

@bradparks can you provide your test project with this problem then?

bradparks commented 11 years ago

hey! I did some more work on it, and found that it's this line:

    FlxControl.player1.setSounds(jumpFX, null, walkFX);

that was causing the problem. It works for Flash, but not for CPP/NEKO. I'm guessing that the assets for sounds aren't right. I'll check into this and get back to you on it.... Seeming like a false alarm to me... Sorry for the noise if so! If not, I'll put together a demo and send it to you....

Incidentally, this type of problem's popped up before for one of the other guys in the forum that was trying to load the mode demo for ios.... I helped him track it down to sound assets then as well... but it was hard to see as the system seems to fail hard on these types of errors.

Have you ever considered adding a DEBUG only assertion check for failure on loading an asset, and raising a VERY noticeable error/stack trace dump for this case? I think the whole code base could definitely benefit from this type of compiler flag (e.g -DDEV_ASSERTIONS) or debugging level tracing on failures during the DEV cycle....

Thanks for your help!

gamedevsam commented 11 years ago

Debugging in cpp is seriously problematic at this point. I made a post on the Haxe google group in the hopes that we'll be able to get more detailed crash information for cpp targets.

bradparks commented 11 years ago

thanks for posting that... i've seen other posts of yours on Stackoverflow regarding it, and I think the whole "debugging" issue (with IDE integration) is a bit problem for Haxe... I know it's good for Flash on Windows/FlashDevelop, but it's not just a Windows world out there anymore ;-)

bradparks commented 11 years ago

I looked into the bug some more, and I don't think it's an asset bug. It's an FlxSound bug, I'd say.

I posted the demo I have for it here:

https://dl.dropbox.com/u/274922/demo_problem.zip

This is with it working in the sense that I disabled the bad code. The bad code line is in Player.hx, and it used to do this:

walkFX.loadEmbedded("Walk", true);

which loaded the walk sound and looped it when played. I removed the looping, so it was just this:

walkFX.loadEmbedded("Walk");

and it works fine, but sounds bad ;-) But the sound still plays, so the media itself is good. It may actually be a cross platform bug... I searched the official demos for a usage of FlxControl, but found none, so I wouldn't be surprised if it actually is a problem on Windows as well.

So it's somewhere in the looping... but with no debugger, it's hard to track down... If anyone knows how to debug neko or CPP on Mac, I'd sure like to know ;-) I've posted about it in NME and Haxe forums, and pm'd Joshua about it, but no response.... I may have to dig into how MonoDevelop works for debugging, as it supposedly used to work for Mac on MonoDevelop 2.8, but I haven't been able to get it to work for 3.1.1 at all.... thanks for the help!

Beeblerox commented 11 years ago

@bradparks i think this is a platform specific bug. There are two types of sounds on cpp and neko targets: sound (plays one time, cannot be controlled, but multiple sounds can be played simultaneously) and music (only one music can play at a time, but you have total control for it). So when you try to play looped sound then you try to control it (by using soundchannel) and this cause the error

bradparks commented 11 years ago

ok! i think I get what you're saying.... i tried looping the sounds with no bg music playing, and that seemed to work fine... so basically one looping sound allowed at a time on cpp/neko targets? if this is the case, is there a way to detect this and throw a nicer developer error if in debug mode? right now for me it was a total lock up on my game... thanks!

Beeblerox commented 11 years ago

@bradparks ok, i'll try to add this error message

gamedevsam commented 11 years ago

so basically one looping sound allowed at a time on cpp/neko targets?

Not being able to loop multiple sounds is a big problem for game developers. I think this is an NME issue, have you tried Haxe 3, Neko 2, and the latest NME version (source)? Maybe it's fixed there.

You will need to pull from haxe3 branch to test it out.