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

A specific space in world json causing a parsing error when calling world.from_json() #1527

Open
ExecMon opened this issue Jan 22, 2025 · 2 comments
Labels
bug Something isn't working needs-repro

Comments

@ExecMon
Copy link

ExecMon commented Jan 22, 2025

Describe the bug

Json parser error when calling: flecs::world.from_json() because of a specific space char between key/value.

To Reproduce

Call flecs::world.from_json() on this json ("Pos" assumed to be a predefined component):

{"results":[{"name":"#1102", "id":1102,"components":{"sys.module.Pos": {"pos":{"x":0, "y":972, "z":0}}}}]}

And this is the error I get:

error: 1: expected }, got ]
{"results":[{"name":"#1102", "id":1102,"components":{"sys.module.Pos": {"pos":{"x":0, "y":972, "z":0}}}}]}
                                                                                                        ^

Removing the space between "sys.module.Pos": and following { solves the issue.

Expected behavior

White space in json shouldn't cause a parsing error.

Additional context

I tried to reproduce this with the flecs::entity.from_json() call but I couldn't, so this issue might be specific to flecs::world.from_json().

The json exported by to_json() does not add this space of course, but using a json library to parse and edit some value may reformat the json leading to some unanticipated whitespace when converting json back to string.

@ExecMon ExecMon added the bug Something isn't working label Jan 22, 2025
@SanderMertens
Copy link
Owner

SanderMertens commented Jan 25, 2025

Are you able to share the component type + reflection code you've used for this? I cannot reproduce this when I create a type with a pos member that is of a type with x, y, z members.

I do get this error when the type does not match the JSON, in which case I get

error: cursor.c: 305: unknown member 'pos' for type 'T'
error: 1: expected }, got ]
{"results":[{"name":"e", "id":1000,"components":{"T": {"pos":{"x":10, "y":20}}}}]}

That's not a bug though, the input is not valid in this case.

@ExecMon
Copy link
Author

ExecMon commented Jan 26, 2025

Sure! I've tested with this module definition:

struct vec3 { float x, y, z; };
struct Pos { vec3 pos; };

namespace sys {
struct module {
	module(flecs::world& ecs) {
		ecs.component<vec3>()
			.member<float>("x")
			.member<float>("y")
			.member<float>("z");
		ecs.component<Pos>()
			.member<vec3>("pos");
	}
};
}

I noticed if I switch the sys.module.Pos in json to use a "Pos" defined as a simple struct Pos { float x, y, z; }; , the parsing error doesn't occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-repro
Projects
None yet
Development

No branches or pull requests

2 participants