Rendering issues with Tilemap

I am getting this odd issue when I am using a Tilemap using any number of layers. As I am working on my own RPG engine, I thought leveraging Tilemap would be a good idea, but it seems some internal issue is causing crashes with it at the moment:


I’ve been exploding trying to figure out what’s causing this error.

I’ve tested using BunnyMark the Tilemap API and it seems to work fine there, but my project, for some reason, caused the above error.

I’ve tried to mimic the order of methods used in BunnyMark in my engine, but to no avail.

You can find the engine, plus a test project, in which you can identify for yourself the error here.

The subject line of code is in rpgfl.display.Map on Line 158. Everything else is fine, I’ve traced code to determine if there was anything wrong with my generation logic, but if there were errors there, it would have crashed then and not at render time (at least I would have thought). What’s ironic is that the callstack makes no mention of the Tilemap in any way, but:


causes the above callstack error. Obviously it can render maps, because I’ve got it working with BunnyMark. I’ve probably overlooked some obvious and missing logic somewhere in the loading code, but I just can’t quite see it. Since one layer has a lot of -1’s on it, I was curious if that would have been an issue. But as it turns out, removing that layer does not solve the problem.

I’ve tested this on Flash, Neko and C++. Neko and C++ just flat out crash. Flash doesn’t crash, it does render but the results are not as you would expect:

I understand I am using the develop branch of OpenFL for most of these tests. The latest stable version and develop seem to have the same results, though.

What I’ve also noticed in the error is that the render call is being called four times, even though there is only one child, which is a bit odd. Whether the Tilemap itself is causing this or not I’m not sure.

Any help would be greatly appreciated.

Okay, I’ve managed to get it to render, apparently trailing new lines was what caused the error on Neko.

Really, that’s strange. Could you share what the code looked like? I didn’t think newlines could be so malicious :slight_smile:

This is the code I used to load layers:

    public static function loadLayersFromCSV(map:Tilemap, mapData:Dynamic)
        var cellWidth:Int = mapData.tilewidth;
        var cellHeight:Int = mapData.tileheight;
        for (i in 0...mapData.layers.length)
            var layerData:Dynamic = mapData.layers[i];
            var set = new Tileset(Assets.getBitmapData(layerData.tileset));
            var cellsX:Int = / cellWidth);
            var cellsY:Int = / cellHeight);
            for (y in 0...cellsY)
                for (x in 0...cellsX)
                    var _x = x * cellWidth;
                    var _y = y * cellHeight;
                    set.addRect(new Rectangle(_x, _y, cellWidth, cellHeight));
            var layer = new TilemapLayer(set);
            var lines:Array<String> = Assets.getText(layerData.file).split('\n');
            var row:Int = 0;
            var column:Int = 0;
            for (line in lines)
                for (cell in line.split(','))
                    var id:Int = Std.parseInt(cell);
                    if (id == -1)
                    var _y = row * cellWidth;
                    var _x = column * cellHeight;
                    var t = new Tile(id, _x, _y);
                column = 0;

More specifically, this line:

var lines:Array<String> = Assets.getText(layerData.file).split('\n');

If you had trailing new lines, and since I didn’t check the line before assuming there were commas or data, Neko would crash. And I suspect any other target for that matter, or just wouldn’t render.

Oh, gotcha, because you would line.split(',') next in the following loop. Makes sense :slight_smile:

Does a null or empty string check fix it?

Probably, but I’m not currently working on it right now. Learning how to produce sound programmatically using lime and OpenFL together :slight_smile: