Skip to content

cute_tiled.h - crash when trying to access a tile's objectgroup for objects (collision) added via tiled's collision editor #399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
detritivore opened this issue Jan 11, 2025 · 2 comments

Comments

@detritivore
Copy link

detritivore commented Jan 11, 2025

Hi, I've been banging my head against a wall (ha!) trying to successfully parse collision data from a tiled map and at first I thought it must be me :-)

Now I'm not so sure..

the issue is with collision data added to a tileset using tiled's collision editor to add a collision object (rectangle).

what I think should be possible is something like:

cute_tiled_tile_descriptor_t* tile = tileset->tiles;
....
cute_tiled_object_t *object = tile->objectgroup->objects;
while (object) {..}
...

this is what is done in the example 'examples_cute_gl_and_tiled_and_spritebatch' print_ functions too.

Using those is also a good way to reproduce it:

using that example's code (just add a return after the call to test_map("test_map.json")) since we don't care about the rest, load the example provided tilemap and observe the printed output.

now open the map with tiled, edit its tileset and add a collision rectangle to any of the tiles, save both the set and the map.
(I've attached that file for convenience, edited with tiled 1.11.0, the collision is added to the 'sign' tile.)

run the test code again, it should crash when it tries to print_tilesets->print_layer(tile->objectgroup)->print_objects(layer->objects).

it crashes with an access violation, leading me to suspect that perhaps something is not being allocated correctly somewhere.

For context:
what I'm actually trying to do, is parse the map data so I can render each tile (works perfectly!) and at the same time, for each tile, lookup its tileset and in it any collision 'objects' and then save that out to some separate container for later processing

test_cute_tiled.json

@RandyGaul
Copy link
Owner

Hi there, I don't super actively work on cute_tiled these days since I'm not using it to make any games currently. Did you notice cute_tiled is made to work with 1.5.0? 1.11 is quite a lot newer, so things might not be matching perfectly. This would probably require some debugging and testing to make sure it's working with the newest Tiled version, which isn't something I can myself spend time on currently.

@detritivore
Copy link
Author

Thanks for getting back to me,

Yeah, I am aware that its not (tested/built with) for newer versions, which is a shame since (afaik) its currently the only 'easy' single header library for doing this (in c), but I guess priorities change and all our time is limited... 😅

To be clear, stuff does work as is even with the newest tiled version (at least the parts I'm using...).
I'm able to parse the information I need from the exported tiled map, and if I access these things 'separately' (as in iterate over the tilesets, store the per-tile collision/object info, then iterate over the different layers for rendering somewhere else.
It just seems like accessing the tileset while going over the layers somehow breaks, not quite sure..

Out of curiosity, what do you use these days?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants