diff --git a/docs/remote/filament.wasm b/docs/remote/filament.wasm index f890818b54..32680cc8f0 100755 Binary files a/docs/remote/filament.wasm and b/docs/remote/filament.wasm differ diff --git a/libs/viewer/src/AutomationEngine.cpp b/libs/viewer/src/AutomationEngine.cpp index 359b884eb2..da117a2e51 100644 --- a/libs/viewer/src/AutomationEngine.cpp +++ b/libs/viewer/src/AutomationEngine.cpp @@ -140,7 +140,11 @@ void AutomationEngine::applySettings(const char* json, size_t jsonLength, View* MaterialInstance* const* materials, size_t materialCount, IndirectLight* ibl, utils::Entity sunlight, LightManager* lm, Scene* scene, Renderer* renderer) { JsonSerializer serializer; - serializer.readJson(json, jsonLength, mSettings); + if (!serializer.readJson(json, jsonLength, mSettings)) { + std::string jsonWithTerminator(json, json + jsonLength); + slog.e << "Badly formed JSON:\n" << jsonWithTerminator.c_str() << io::endl; + return; + } viewer::applySettings(mSettings->view, view); for (size_t i = 0; i < materialCount; i++) { viewer::applySettings(mSettings->material, materials[i]); diff --git a/libs/viewer/src/Settings.cpp b/libs/viewer/src/Settings.cpp index 61393afd1f..3d33d7ac17 100644 --- a/libs/viewer/src/Settings.cpp +++ b/libs/viewer/src/Settings.cpp @@ -1205,9 +1205,9 @@ static std::ostream& operator<<(std::ostream& out, const DepthOfFieldOptions& in << "\"enabled\": " << to_string(in.enabled) << ",\n" << "\"filter\": " << (in.filter) << ",\n" << "\"nativeResolution\": " << (in.nativeResolution) << ",\n" - << "\"foregroundRingCount\": " << (in.foregroundRingCount) << ",\n" - << "\"backgroundRingCount\": " << (in.backgroundRingCount) << ",\n" - << "\"fastGatherRingCount\": " << (in.fastGatherRingCount) << ",\n" + << "\"foregroundRingCount\": " << int(in.foregroundRingCount) << ",\n" + << "\"backgroundRingCount\": " << int(in.backgroundRingCount) << ",\n" + << "\"fastGatherRingCount\": " << int(in.fastGatherRingCount) << ",\n" << "\"maxForegroundCOC\": " << (in.maxForegroundCOC) << ",\n" << "\"maxBackgroundCOC\": " << (in.maxBackgroundCOC) << "\n" << "}"; @@ -1330,7 +1330,6 @@ bool JsonSerializer::readJson(const char* jsonChunk, size_t size, Settings* out) int tokenCount = jsmn_parse(&parser, jsonChunk, size, nullptr, 0); if (tokenCount <= 0) { - slog.e << "Badly formed JSON." << io::endl; return false; } @@ -1342,7 +1341,6 @@ bool JsonSerializer::readJson(const char* jsonChunk, size_t size, Settings* out) if (tokenCount <= 0) { free(tokens); - slog.e << "Badly formed JSON." << io::endl; return false; } diff --git a/libs/viewer/tests/test_settings.cpp b/libs/viewer/tests/test_settings.cpp index 1273839a5d..6eadab3de4 100644 --- a/libs/viewer/tests/test_settings.cpp +++ b/libs/viewer/tests/test_settings.cpp @@ -162,6 +162,23 @@ TEST_F(ViewSettingsTest, JsonTestDefaults) { ASSERT_EQ(serializer.writeJson(settings2), serializer.writeJson(settings3)); } +TEST_F(ViewSettingsTest, JsonTestSerialization) { + auto canParse = [](bool parseResult, std::string json) { + if (parseResult) { + return testing::AssertionSuccess() << "Settings can be serialized."; + } else { + return testing::AssertionFailure() << "JSON has errors:\n" << json.c_str() << std::endl; + } + }; + + JsonSerializer serializer; + Settings outSettings = {}; + std::string jsonstr = serializer.writeJson(outSettings); + Settings inSettings = {}; + bool result = serializer.readJson(jsonstr.c_str(), jsonstr.size(), &inSettings); + ASSERT_TRUE(canParse(result, jsonstr)); +} + TEST_F(ViewSettingsTest, JsonTestMaterial) { JsonSerializer serializer; Settings settings = {0};