diff --git a/src/ScenarioRepository.cpp b/src/ScenarioRepository.cpp index b86ff251e0..d05f3b0e72 100644 --- a/src/ScenarioRepository.cpp +++ b/src/ScenarioRepository.cpp @@ -194,7 +194,7 @@ public: bool TryRecordHighscore(const utf8 * scenarioFileName, money32 companyValue, const utf8 * name) override { - const scenario_index_entry * scenario = GetByFilename(scenarioFileName); + scenario_index_entry * scenario = GetByFilename(scenarioFileName); if (scenario != nullptr) { // Check if record company value has been broken or the highscore is the same but no name is registered @@ -205,20 +205,21 @@ public: if (highscore == nullptr) { highscore = InsertHighscore(); - scenario->highscore->timestamp = platform_get_datetime_now_utc(); + highscore->timestamp = platform_get_datetime_now_utc(); + scenario->highscore = highscore; } else { if (highscore->name != nullptr) { - scenario->highscore->timestamp = platform_get_datetime_now_utc(); + highscore->timestamp = platform_get_datetime_now_utc(); } SafeFree(highscore->fileName); SafeFree(highscore->name); } - scenario->highscore->fileName = String::Duplicate(Path::GetFileName(scenario->path)); - scenario->highscore->name = String::Duplicate(name); - scenario->highscore->company_value = companyValue; + highscore->fileName = String::Duplicate(Path::GetFileName(scenario->path)); + highscore->name = String::Duplicate(name); + highscore->company_value = companyValue; SaveHighscores(); return true; } @@ -499,7 +500,7 @@ private: for (size_t i = 0; i < _highscores.size(); i++) { scenario_highscore_entry * highscore = _highscores[i]; - scenario_index_entry * scenerio = GetByPath(highscore->fileName); + scenario_index_entry * scenerio = GetByFilename(highscore->fileName); if (scenerio != nullptr) { scenerio->highscore = highscore; diff --git a/src/core/String.cpp b/src/core/String.cpp index 73238e35ad..2240ffd32f 100644 --- a/src/core/String.cpp +++ b/src/core/String.cpp @@ -177,8 +177,13 @@ namespace String utf8 * Duplicate(const utf8 * src) { - size_t srcSize = SizeOf(src); - return Memory::DuplicateArray(src, srcSize + 1); + utf8 * result = nullptr; + if (src != nullptr) + { + size_t srcSize = SizeOf(src); + result = Memory::DuplicateArray(src, srcSize + 1); + } + return result; } utf8 * DiscardUse(utf8 * * ptr, utf8 * replacement) diff --git a/src/scenario.c b/src/scenario.c index 53f84768fe..c5689d500b 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -353,7 +353,7 @@ void scenario_success() */ void scenario_success_submit_name(const char *name) { - if (scenario_repository_try_record_highscore(_scenarioFileName, gScenarioCompanyValueRecord, NULL)) + if (scenario_repository_try_record_highscore(_scenarioFileName, gScenarioCompanyValueRecord, name)) { safe_strcpy(gScenarioCompletedBy, name, 32); }