Skip to content
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

[cute_tiled_h]: Field name points to wrong memory address. #368

Open
KlemenPl opened this issue Nov 8, 2023 · 2 comments
Open

[cute_tiled_h]: Field name points to wrong memory address. #368

KlemenPl opened this issue Nov 8, 2023 · 2 comments

Comments

@KlemenPl
Copy link

KlemenPl commented Nov 8, 2023

When naming objects in collision editor I can't for some reason access that name. I have 2 objects (first is named ˙test`):

image

To read the 2 objects I use the following code:

#include <cute_tiled.h>
#include <stdio.h>

int main() {
    cute_tiled_tileset_t *tileset = cute_tiled_load_external_tileset("test.tsj", NULL);

    cute_tiled_tile_descriptor_t *tile = tileset->tiles;

    printf("Tileset name: %p %s\n", tileset->name.ptr, tileset->name.ptr);
    while (tile) {
        cute_tiled_layer_t *layer = tile->objectgroup;
        cute_tiled_object_t *object = layer->objects;

        while (object) {
            printf("[%p]: ellipse:%d x:%2.f y:%2.f w:%2.f h:%2.f\n",
                   object->name.ptr, object->ellipse,
                   object->x, object->y, object->width, object->height);

            object = object->next;
        }

        tile = tile->next;
    }

    cute_tiled_free_external_tileset(tileset);
}

I get the correct position and size of rectangles, but the name points to invalid memory address. Derefrencing it, causes segfault.

Tileset name: 0x7f12107bf038 test
[0x100000005]: ellipse:0 x: 6 y: 6 w: 4 h: 4
[0x100000002]: ellipse:0 x: 2 y: 2 w:12 h:12

In exported json file I can see that it has correct name test.

Exported json: test.json
Tiled tileset: tileset.zip

I am wondering what exactly am I doing wrong and how do I access to the name field.

@KlemenPl
Copy link
Author

KlemenPl commented Nov 8, 2023

This is also an issue with custom properties.

Exported tileset with custom property: test.json

image

@RobLoach
Copy link
Contributor

.ptr is the correct way to get the string. It could be that name isn't loaded for each object.

printf("%s/n", object->name.ptr);

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

No branches or pull requests

2 participants