【问题标题】:Haxe application exits when deployed to windowsHaxe 应用程序在部署到 Windows 时退出
【发布时间】:2014-08-12 06:32:45
【问题描述】:

我正在使用 haxe/openfl 制作游戏引擎。到目前为止,它只是应该显示属于事物对象的图像。到目前为止,我构建的内容在部署为 Flash 应用程序时可以完美运行,但在我将其部署为 Windows 应用程序时会立即关闭。它只是在 html5 中创建一个空白屏幕。我没有测试过其他目标。我正在使用 HIDE,每次崩溃时,HIDE 都会显示消息:“文件 c:\Users\Adu\Documents\HaxeProjects\Downloaded\Export\windows\cpp\bin\Downloaded.exe 已更改。重新加载?”并给我选择是或否。我的回答似乎并没有改变这种情况。当我手动进入导出目录并运行应用程序时,它给出了错误:“错误自定义([file_write,stderr])。这是我的代码:

主要:

package;
import openfl.display.Graphics;

import openfl.Assets;
import openfl.display.Bitmap;
import openfl.display.Sprite;
import openfl.events.Event;
import openfl.Lib;
import openfl.text.TextField;
import openfl.text.TextFormat;
import openfl.ui.Keyboard;
import openfl.events.*;

class Main
{

    static var obj(default,default):ObjectManager; //contains the list that all gameobjects add themselves to
    static var stage = Lib.current.stage;

    public static function main() // this is the gameloop
        {
            // static entry point
            startUp();
            var running = true; // gives me a way to exit the gameloop
            while (running)
                {
                    logic();
                    render();
                    Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, function(event)
                                {
                                    if (event.keyCode == Keyboard.ESCAPE)
                                        {
                                            running=false;
                                        }
                                });
                }
        }

    static function startUp() // runs once, when the game is started
        {
            obj= new ObjectManager();
            stage.align = openfl.display.StageAlign.TOP_LEFT;
            stage.scaleMode = openfl.display.StageScaleMode.NO_SCALE;
        }           


    static function logic() // loops, this handles the logic
        {
            var thing = new GameObject("assets/pixel_thing.png", 1, obj);

            var mech = new GameObject("assets/mechwarrior.png", 0, obj);
        }

    static function render() // runs right after logic and draws everything to the screen
        {
            for (i in obj.objects) //iterates through a list of gabeobjects and draws them, it is 2 dimensional so that I can draw objects in blocks
                {
                    for (j in i)
                        {
                            Lib.current.addChild(j);
                        }

                }


        }   


}

游戏对象:

package ;
import openfl.display.BitmapData;
import openfl.Assets;
import openfl.display.Bitmap;
import openfl.display.Sprite;
import openfl.events.Event;
import openfl.Lib;
import openfl.text.TextField;
import openfl.text.TextFormat;

class GameObject extends Sprite
{
public function new(?image:String, zOrder:Int, objectManager:ObjectManager) // image is the image, zorder is which layer it's drawn on, lower layers are drawn on top objectmanager is just there to help me pass the list to the object
{
    super();

    var data = Assets.getBitmapData(image);//this is the image data
    var bitmap:Bitmap = new Bitmap(data);//this is the actual image
    Lib.current.stage.addChild(bitmap);//this sraws the image when the object is instantiated
    objectManager.objects[zOrder].push(this);// this adds it to the list of objects
}
}

对象管理器:

package ;


class ObjectManager
{
public var objects = new Array<Array<GameObject>>();
}

为什么它可以在flash上​​运行而不是windows?我该如何解决这个问题?

【问题讨论】:

    标签: windows haxe openfl


    【解决方案1】:

    首先 - 这在 flash 上也不能正常工作。您是在 Flash 调试播放器中运行它吗?如果你不这样做,我认为是这种情况,你不会看到任何异常。

    此行存在空引用错误:

    objectManager.objects[zOrder].push(this);// this adds it to the list of objects

    您正在访问索引zOrder 处的数组,该数组不存在。 objects 正在初始化为 [],其中不包括“内部数组”(它真的不知道应该有多少个?)。


    现在,默认情况下,Windows 版本不会为您提供非常有用的调试信息。一种简单的解决方法是使用 neko(其行为与 hxcpp 构建大部分相同,但编译速度更快且性能更差)进行调试,默认情况下您会在崩溃时获得堆栈跟踪。

    果然和flash是一样的问题,唯一的区别是native构建crash,而flash只是“忽略”并尝试继续。

    Invalid field access : objects
    Called from GameObject::new line 92
    Called from GameObject::$init line 83
    Called from Main::logic line 61
    Called from Main::main line 38
    Called from Reflect::callMethod line 58
    Called from ApplicationMain::main line 91
    Called from openfl.Lib::create line 113
    

    要获得更好的 hxcpp 构建调试信息,您可能需要查看 crashdumper 库。

    【讨论】:

    • 非常感谢,完美回答了我的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    • 2013-07-03
    • 2016-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多