u_config_json: Create root node on save if no config file loaded

If no config file is loaded, json->root can be uninitialized instead of NULL.

Fixes #117
This commit is contained in:
Christoph Haag 2021-04-04 20:58:47 +02:00
parent 727612c0a5
commit 2b962a5bfb

View file

@ -378,7 +378,7 @@ u_config_write(struct u_config_json *json)
void void
u_config_json_save_calibration(struct u_config_json *json, struct xrt_settings_tracking *settings) u_config_json_save_calibration(struct u_config_json *json, struct xrt_settings_tracking *settings)
{ {
if (!json->root) { if (!json->file_loaded) {
u_config_json_make_default_root(json); u_config_json_make_default_root(json);
} }
cJSON *root = json->root; cJSON *root = json->root;
@ -435,7 +435,7 @@ make_pose(struct xrt_pose *pose)
void void
u_config_json_save_overrides(struct u_config_json *json, struct xrt_tracking_override *overrides, size_t num_overrides) u_config_json_save_overrides(struct u_config_json *json, struct xrt_tracking_override *overrides, size_t num_overrides)
{ {
if (!json->root) { if (!json->file_loaded) {
u_config_json_make_default_root(json); u_config_json_make_default_root(json);
} }
cJSON *root = json->root; cJSON *root = json->root;