2

我有一个可以在屏幕上拖动的精灵。我希望能够将这个精灵拖到一个区域(框)中。现在我只能把精灵放到盒子里,但是当我直接拖动它时,程序崩溃了。

*我在 FlashDevelop 中开发,但 Windows 给了我在 VS 中调试的 av 选项。

我在VS中调试并得到这个错误:

Unhandled exception at 0x00ACCEE9 in Proj.exe: 0xC0000005: Access violation reading location 0x00000008.

相关代码:

class Drag extends FlxGroup {

var mouseJoint:DistanceJoint;

public inline function registerPhysSprite(spr:FlxNapeSprite)
{
    MouseEventManager.add(spr, createMouseJoint);

}

function createMouseJoint(spr:FlxSprite)
{

    var body:Body = cast(spr, FlxNapeSprite).body;

    mouseJoint = new DistanceJoint(FlxNapeState.space.world, body, new Vec2(FlxG.mouse.x, FlxG.mouse.y),
                            body.worldPointToLocal(new Vec2(FlxG.mouse.x, FlxG.mouse.y)), 0, 0);

    mouseJoint.space = FlxNapeState.space;
}


override public function update():Void
{
    super.update();

    if (mouseJoint != null)
    {
        mouseJoint.anchor1 = new Vec2(FlxG.mouse.x, FlxG.mouse.y);

        if (FlxG.mouse.justReleased)
        {
            mouseJoint.space = null;
        }
    }

 }

}

class PlayState extends FlxNapeState {
    override public function create()
    {
    super.create();
    bgColor = FlxColor.BLACK;
    napeDebugEnabled = true;

    var light = new Light(10, 10);
    var box = new Box(100, 100);
    var drag:Drag;

    createWalls(1, 1, 1024, 768, 10, new Material(1, 1, 2, 1, 0.001));

    add(light);
    add(box);

    drag = new Drag();
    add(drag);                                                         
    drag.registerPhysSprite(light);

    light.body.velocity.y = 200;

    FlxNapeState.space.listeners.add(new InteractionListener(
        CbEvent.BEGIN, 
        InteractionType.COLLISION, 
        Light.CB_TYPE,
        Box.CB_TYPE,
        collideLightBox));
    }

    function collideLightBox(callback:InteractionCallback)
    {
        var light:Light = cast callback.int1.castBody.userData.sprite;
        light.kill();
    }
}

class Light extends FlxNapeSprite {
    public static var CB_TYPE(default, null) = new CbType();

    public function new(x:Float, y:Float)
    {
        super(x, y);
        makeGraphic(10, 10, FlxColor.TRANSPARENT);
        var radius = 5;
        drawCircle(5, 5, radius, FlxColor.WHITE);
        createCircularBody(radius);
        body.cbTypes.add(CB_TYPE);

        body.userData.sprite = this;
    }
}

class Box extends FlxNapeSprite {
    public static var CB_TYPE(default, null) = new CbType();

    public function new(x:Float, y:Float)
    {
        super(x, y);
        makeGraphic(100, 50, FlxColor.GREEN);
        createRectangularBody(width, height);
        body.cbTypes.add(CB_TYPE);
        body.type = BodyType.STATIC;
    }
}
4

1 回答 1

0

如果您可能正在访问空指针,请考虑以下问题中给出的答案: Why is this Haxe try-catch block still crashing, when using Release mode for C++ target

这样您就可以在 hxcpp 中打开空指针检查,以便获得更好的调试信息。

此外,如果您尝试直接在 FlashDevelop 中调试 hxcpp(单步调试等),该功能尚未发布,但我最近与团队进行了交谈,他们正在努力。

于 2015-06-08T15:10:55.697 回答