Android HaxeFlixel游戏中与声音相关的间歇性硬碰撞

时间:2016-08-24 09:16:40

标签: android logcat haxe openfl haxeflixel

我在使用HaxeFlixel和OpenFL 2.1.3编写针对Android的游戏时遇到了问题。游戏随机崩溃,有时在开始后不久,有时几分钟后崩溃,并立即关闭应用程序,没有任何消息或明显的错误。无论出于何种原因,我在连接IDE的情况下调试应用程序时遇到困难,所以我在设备上运行时附加了logcat,并将其缩小到以下跟踪:

I/trace   ( 8505): Lib.hx:324: Null Object Reference
I/trace   ( 8505): Called from openfl._v2.display.Stage.__render (openfl/_v2/display/Stage.hx line 1035)
I/trace   ( 8505): Called from openfl._v2.display.DisplayObjectContainer.__broadcast (openfl/_v2/display/DisplayObjectContainer.hx line 280)
I/trace   ( 8505): Called from openfl._v2.display.DisplayObject.__broadcast (openfl/_v2/display/DisplayObject.hx line 174)
I/trace   ( 8505): Called from openfl._v2.display.DisplayObject.__dispatchEvent (openfl/_v2/display/DisplayObject.hx line 195)
I/trace   ( 8505): Called from openfl._v2.events.EventDispatcher.dispatchEvent (openfl/_v2/events/EventDispatcher.hx line 100)
I/trace   ( 8505): Called from openfl._v2.events.Listener.dispatchEvent (openfl/_v2/events/EventDispatcher.hx line 270)
I/trace   ( 8505): Called from flixel.FlxGame.onEnterFrame (flixel/FlxGame.hx line 493)
I/trace   ( 8505): Called from flixel.FlxGame.step (flixel/FlxGame.hx line 648)
I/trace   ( 8505): Called from flixel.FlxGame.update (flixel/FlxGame.hx line 696)
I/trace   ( 8505): Called from flixel.system.frontEnds.SoundFrontEnd.update (flixel/system/frontEnds/SoundFrontEnd.hx line 278)
I/trace   ( 8505): Called from flixel.group.FlxTypedGroup.update (flixel/grou
I/WindowState(  467): WIN DEATH: Window{2b71e64d u0 com.al.shb/com.al.shb.MainActivity}
W/WindowManager(  467): Force-removing child win Window{d7de13 u0 SurfaceView} from container Window{2b71e64d u0 com.al.shb/com.al.shb.MainActivity}
W/WindowManager(  467): Failed looking up window
W/WindowManager(  467): java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@2038b502 does not exist
W/WindowManager(  467):     at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8539)
W/WindowManager(  467):     at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8530)
W/WindowManager(  467):     at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:1142)
W/WindowManager(  467):     at android.os.BinderProxy.sendDeathNotice(Binder.java:551)
I/WindowState(  467): WIN DEATH: null
I/InputDispatcher(  467): Dropping event because there is no touchable window at (87, 430).
I/Zygote  (  130): Process 8505 exited cleanly (1)
I/ActivityManager(  467): Process com.al.shb (pid 8505) has died
W/ActivityManager(  467): Force removing ActivityRecord{3f0e8887 u0 com.al.shb/.MainActivity t13}: app died, no saved state

SoundFrontEnd / FlxTypedGroup会暗示这是游戏中音效组的问题。声音看起来很好,并编码为.ogg文件。当它试图播放任何声音时它不会崩溃,它更像是随机发生的。

我按照HaxeFlixel的建议缓存Android目标的声音,但我将它们缓存在我的Main类的init()中,这应该不是问题:

private function setupGame():Void
{
    var stageWidth:Int = Lib.current.stage.stageWidth;
    var stageHeight:Int = Lib.current.stage.stageHeight;

    if (zoom == -1)
    {
        var ratioX:Float = stageWidth / gameWidth;
        var ratioY:Float = stageHeight / gameHeight;
        zoom = Math.min(ratioX, ratioY);
        gameWidth = Math.ceil(stageWidth / zoom);
        gameHeight = Math.ceil(stageHeight / zoom);
    }

    #if android
    FlxG.sound.cache("button");
    FlxG.sound.cache("t1");
    FlxG.sound.cache("t2");
    FlxG.sound.cache("fx");
    #end

    addChild(new FlxGame(gameWidth, gameHeight, initialState, zoom, framerate, framerate, skipSplash, startFullscreen));
}

使用FlxG.sound.play("button")播放。

我还看了一下OpenFL Lib.hx来检查Null Object Reference,这似乎是下面方法中底部代码块的问题,但我怀疑这是一个红色鲱鱼:

public static function rethrow (error:Dynamic):Void {   
    var event = new UncaughtErrorEvent (UncaughtErrorEvent.UNCAUGHT_ERROR, true, true, error);

    if (__uncaughtExceptionHandler != null && __uncaughtExceptionHandler (event)) {
        return;
    }

    Lib.current.loaderInfo.uncaughtErrorEvents.dispatchEvent (event);   

    if (!event.__getIsCancelled ()) {
        var message = "";
        if (error != null && error != "") {
            message = error + "";
        }

        var stack = CallStack.exceptionStack ();
        if (stack.length > 0) {
            message += CallStack.toString (stack) + "\n";
        } else {
            message += "\n";
        }

        #if (mobile && !ios)
        trace (message);
        #else
        Sys.stderr ().write (Bytes.ofString (message));
        #end
        Sys.exit (1);
    }
}

值得注意的是,如果我定位Flash或Windows根本没有问题,那么只有在定位Android时才会这样。不同之处在于,当Android使用mp3时,Flash和Windows会使用ogg个编码文件。

0 个答案:

没有答案