tmx_load returns NULL on OS X
Bambofy opened this issue · 5 comments
void loadmap(const char* mname, tmx_map** map) {
assert(mname != NULL);
assert(map != NULL);
*map = tmx_load("maps/island.tmx");
if (*map == NULL) {
throw std::runtime_error("Couldn't load map.");
}
assert(*map != NULL);
}
With this test data https://github.com/mapeditor/tiled/tree/master/examples/rpg results in this error:
"xml parser: missing 'id' attribute in the 'layer' element"
Hi,
Thanks for the report.
According to the documentation id
is a mandatory parameter, but as support was added recently older maps may not have ids on layers.
else
bloc to remove here: https://github.com/baylej/tmx/blame/master/src/tmx_xml.c#L490
If i add id="1" to all of the elements, strangely it still prints the error.
Removing the else worked though
The thing is that since version 1.2 of Tiled, each layer gets a unique ID, you could fix this file by opening it in Tiled then clicking on File > Save.
There is also this function: https://libtmx.readthedocs.io/en/latest/functions.html#c.tmx_find_layer_by_id
Fortunately, layer IDs start at 1, so 0 is not a correct layer ID, I'll just remove the else block and layers without ID will have id=0.