0

I am making a game engine in haxe/openfl. so far it's just supposed to display the image that belongs to the thing object. what I have built so far runs perfectly on when deployed as a flash application, but closes instantly when I deploy it as a windows application. It just creates a blank screen in html5. I have not tested other targets. I am using HIDE, and every time it crashes, HIDE brings up the message: "File c:\Users\Adu\Documents\HaxeProjects\Downloaded\Export\windows\cpp\bin\Downloaded.exe was changed. Reload?" and gives me the options yes or no. My answer doesn't seem to change the situation. when I manually go into the export directory and run the application, it gives the error: "Error Custom([file_write,stderr]). Here is my code:

Main:

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);
                        }

                }


        }   


}

GameObject:

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>>();
}

why is it that it works on flash but not windows? How do I fix this?

1 Answers1

1

First off - this doesn't work fine on flash either. Are you running this in the flash debug player? If you don't, which I assume is the case, you won't see any exceptions.

There's a null reference error at this line:

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

You are accessing the array at index zOrder, which doesn't exist. objects is being initialized to [], which does not include the "inner arrays" (it can't, really, how would it know how many of them there should be?).


Now, Windows builds don't give you very helpful debug information by default. A simple way around is to use neko (which mostly behaves the same as hxcpp builds, except it compiles faster and performs worse) for debugging, where you get a stacktrace by default on crashes.

Sure enough, it's the same issue as in flash, the only difference is that native builds crash while flash just "ignores it" and tries to carry on.

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

For better hxcpp build debug info, you might want to have a look at the crashdumper lib.

Gama11
  • 31,714
  • 9
  • 78
  • 100