u_config_json: Fix saving when no config file exists

If json->root was null, it would write a config file containing only (null).
This commit is contained in:
Christoph Haag 2021-03-24 17:33:46 +01:00
parent e066f6a828
commit dad5c6d5d8

View file

@ -354,6 +354,12 @@ u_config_json_get_tracking_settings(struct u_config_json *json, struct xrt_setti
return true;
}
static void
u_config_json_make_default_root(struct u_config_json *json)
{
json->root = cJSON_CreateObject();
}
static void
u_config_write(struct u_config_json *json)
{
@ -371,6 +377,9 @@ u_config_write(struct u_config_json *json)
void
u_config_json_save_calibration(struct u_config_json *json, struct xrt_settings_tracking *settings)
{
if (!json->root) {
u_config_json_make_default_root(json);
}
cJSON *root = json->root;
cJSON *t = cJSON_GetObjectItem(root, "tracking");
@ -425,6 +434,9 @@ make_pose(struct xrt_pose *pose)
void
u_config_json_save_overrides(struct u_config_json *json, struct xrt_tracking_override *overrides, size_t num_overrides)
{
if (!json->root) {
u_config_json_make_default_root(json);
}
cJSON *root = json->root;
cJSON *t = cJSON_GetObjectItem(root, "tracking");