-
-
Notifications
You must be signed in to change notification settings - Fork 479
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
Comments
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 I do get this error when the type does not match the JSON, in which case I get
That's not a bug though, the input is not valid in this case. |
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 |
Can you try this on the latest release? This code runs for me without errors in 4.0.4: #include <flecs.h>
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");
}
};
}
int main(const int argc, const char **argv)
{
flecs::world world;
world.import<sys::module>();
world.from_json(
"{\"results\":[{\"name\":\"#1102\", \"id\":1102,\"components\":{\"sys.module.Pos\": {\"pos\":{\"x\":0, \"y\":972, \"z\":0}}}}]}"
);
return 0;
} |
Just tried that code on current master and it ran without errors for me as well. So I did some more testing and I arrived at this which should reproduce the issue: #include <iostream>
#include <flecs.h>
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");
}
};
}
int main(const int argc, const char **argv)
{
{
flecs::world world;
world.import<sys::module>();
std::cout << "Unregistered component without space:\n";
// Doesn't error
world.from_json(
"{\"results\":[{\"name\":\"#1102\",\"id\":1102,\"components\":{\"NotPos\":{\"pos\":{\"x\":0, \"y\":972, \"z\":0}}}}]}"
);
}
{
flecs::world world;
world.import<sys::module>();
std::cout << "Unregistered component with space:\n";
// Thorws error
world.from_json(
"{\"results\":[{\"name\":\"#1102\", \"id\":1102,\"components\":{\"NotPos\": {\"pos\":{\"x\":0, \"y\":972, \"z\":0}}}}]}"
);
}
return 0;
} I'm not sure yet but if this is specific to parsing unregistered components, then it's probably a minor issue/edge case. |
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):And this is the error I get:
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 toflecs::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.The text was updated successfully, but these errors were encountered: