Haxe应用程序在部署到Windows时退出

时间:2014-08-12 06:32:46

标签: windows haxe openfl

我正在使用haxe / openfl制作游戏引擎。到目前为止它只是应该显示属于thing对象的图像。到目前为止我构建的内容在部署为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
}
}

的ObjectManager:

package ;


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

为什么它适用于闪存但不适用于Windows?我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

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

此行有一个空引用错误:

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

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


现在,Windows构建默认情况下不会为您提供非常有用的调试信息。一个简单的方法是使用neko(其主要行为与hxcpp构建相同,除了它编译速度更快,性能更差)进行调试,默认情况下在崩溃时获得堆栈跟踪。

果然,它与flash中的问题相同,唯一的区别是本机构建崩溃,而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库。