Skip to content

NullPointerException when loading IntGrid layer without an associated tileset #1

@fourlastor

Description

@fourlastor

I tried loading a map I made with LDtk, where one of the layers is an intgrid without an associated tileset (I'm using autotile layers for the actual output), but while loading there's a NPE thrown:

Exception in thread "main" java.lang.NullPointerException
	at java.base/java.io.File.<init>(File.java:278)
	at com.badlogic.gdx.files.FileHandle.<init>(FileHandle.java:81)
	at com.badlogic.gdx.backends.lwjgl3.Lwjgl3FileHandle.<init>(Lwjgl3FileHandle.java:29)
	at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Files.internal(Lwjgl3Files.java:42)
	at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:110)
	at com.redsponge.ldtkgdx.LDTKTileLayer.<init>(LDTKTileLayer.java:16)
	at com.redsponge.ldtkgdx.LDTKLevel.parseLayer(LDTKLevel.java:73)
	at com.redsponge.ldtkgdx.LDTKLevel.<init>(LDTKLevel.java:52)
	at com.redsponge.ldtkgdx.LDTKMap.parseLevel(LDTKMap.java:40)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at com.redsponge.ldtkgdx.LDTKMap.load(LDTKMap.java:36)
	at com.redsponge.ldtkgdx.LDTKMap.<init>(LDTKMap.java:27)
	at io.github.fourlastor.jamjam.LdtkScreen.<init>(LdtkScreen.kt:15)
	at io.github.fourlastor.jamjam.JamGame.create(JamGame.kt:9)
	at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.initializeListener(Lwjgl3Window.java:433)
	at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.update(Lwjgl3Window.java:381)
	at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.loop(Lwjgl3Application.java:143)
	at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(Lwjgl3Application.java:116)
	at io.github.fourlastor.jamjam.DesktopLauncherKt.main(DesktopLauncher.kt:12)
	at io.github.fourlastor.jamjam.DesktopLauncherKt.main(DesktopLauncher.kt)

I think this happens because of this line, which expects a tileset file to be present.

This is the level json content (I cut out some parts for clarity, you can create a test file by having a single level in an LDtk file with an IntGrid layer with no tileset associated), where the intgrid's __tilesetRelPath is null:

{
	"__header__": {
		"fileType": "LDtk Project JSON",
		"app": "LDtk",
		"doc": "https://ldtk.io/json",
		"schema": "https://ldtk.io/files/JSON_SCHEMA.json",
		"appAuthor": "Sebastien 'deepnight' Benard",
		"appVersion": "1.1.3",
		"url": "https://ldtk.io"
	},
	"jsonVersion": "1.1.3",
	"appBuildId": 458364,
	"levels": [
		{
			"identifier": "Level_0",
			"iid": "4d1cda10-dbe0-11ec-a7eb-cb7b38a20b96",
			"uid": 0,
			"worldX": 0,
			"worldY": 0,
			"worldDepth": 0,
			"pxWid": 256,
			"pxHei": 256,
			"__bgColor": "#696A79",
			"bgColor": null,
			"useAutoIdentifier": true,
			"bgRelPath": null,
			"bgPos": null,
			"bgPivotX": 0.5,
			"bgPivotY": 0.5,
			"__smartColor": "#ADADB5",
			"__bgPos": null,
			"externalRelPath": null,
			"fieldInstances": [],
			"layerInstances": [
				{
					"__identifier": "IntGrid",
					"__type": "IntGrid",
					"__cWid": 16,
					"__cHei": 16,
					"__gridSize": 16,
					"__opacity": 1,
					"__pxTotalOffsetX": 0,
					"__pxTotalOffsetY": 0,
					"__tilesetDefUid": null,
					"__tilesetRelPath": null,
					"iid": "83bc4fb0-dbe0-11ec-a7eb-53534ccf5b88",
					"levelId": 0,
					"layerDefUid": 2,
					"pxOffsetX": 0,
					"pxOffsetY": 0,
					"visible": true,
					"optionalRules": [],
					"intGridCsv": [
						1,1,1,1,1,1,0,1,0,1,0,1,1,1,1,1,1,0,1,0,1,1,0,1,1,1,0,1,1,0,0,0,1,1,0,
						0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,
						0,0,0,0,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
						0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
						0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,
						0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,0,0,0,0,
						0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,
						0,0,0,0,0,0,0,0,0,0,0
					],
					"autoLayerTiles": [],
					"seed": 30204,
					"overrideTilesetUid": null,
					"gridTiles": [],
					"entityInstances": []
				}
			],
			"__neighbours": []
		}
	],
	"worlds": []
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions