-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Float values are not serialized in NUI callback #2171
Comments
There is a case of a missing |
Probably, that is the case. At least FLOAT32 and FLOAT may be encoded as Double. But we have only Float getter/setter were added only after this PR in rapidjson |
Trying to round-trip float32's may lead some to backwards compatibility problems. Some care, if possible, will be required. The missing |
I think FLOAT32/float can be treated as double and returned as double safely. It will not break any backward compatibility issues (because floats did not work) and would not affect new code, if you continue using doubles |
The Problem
I'm trying to use modern way of returning data from C# Client to NUI, utilizing result(object) call. For some reason
float
values are not serialized and equal null at NUI side.Reproduce code
Possible problem
When I tested different types:
float _a, double _b, int _c, long _d, string _e, bool _f
, it seems like only float is not converted correctlyI observed, that value of this
result
is serialized first to JSON, and then to MessagePack.fivem/code/components/nui-resources/src/ResourceUICallbacks.cpp
Line 23 in 81fd97f
Possibly, JSON part serializes
floats
wrong.Workaround
For now I have 2 workarounds:
double
everywhere instead offloat
result(JsonConvert.SerializeObject(new { ok = true, speed = vehicleSpeed }));
The text was updated successfully, but these errors were encountered: