部署到windows时,Haxe应用程序将退出

部署到windows时,Haxe应用程序将退出,windows,haxe,openfl,Windows,Haxe,Openfl,我正在用haxe/openfl制作一个游戏引擎。到目前为止,它只是应该显示属于对象的图像。到目前为止,我构建的应用程序在部署为flash应用程序时可以完美运行,但在部署为windows应用程序时会立即关闭。它只是在html5中创建了一个空白屏幕。我没有测试其他目标。我正在使用HIDE,每次它崩溃时,HIDE都会显示消息:“文件c:\Users\Adu\Documents\HaxeProjects\Downloaded\Export\windows\cpp\bin\Downloaded.exe已更

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

主要内容:

游戏对象:

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>>();
}
包;
类对象管理器
{
public var objects=new Array();
}

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

首先-这在flash上也不能很好地工作。您是否在flash调试播放器中运行它?如果您不运行,我假设是这样,您将不会看到任何异常

此行存在空引用错误:

objectManager.objects[zOrder].push(this);//这会将其添加到对象列表中

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


现在,默认情况下,Windows版本不会提供非常有用的调试信息。一种简单的解决方法是使用neko(其行为与hxcpp版本基本相同,只是编译速度更快,性能更差)进行调试,默认情况下,在崩溃时会得到stacktrace

果不其然,这与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构建调试信息,您可能需要查看库。

非常感谢,这完美地回答了我的问题
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