Wire main menu Options/Quit through the cutscene, fix locale crashes
Options and Quit now route through main_menu.jsonc markers the same way New Game does, with a new QUIT_GAME cutscene item type ending the process directly once quit is confirmed via MODAL_OPTIONS_MARKERS (whose "message" field is now optional, defaulting to "" like "title"). Fixes two crashes surfaced along the way: - uiModalLocalize asserted on an empty locale key instead of treating it as "nothing to show" - hit as soon as a modal omitted a title or message. - assetLocaleGetString's new empty-message-ID guard broke the PO format's own header-read convention (messageId "") used internally by assetLocaleLoaderAsync, crashing on every boot. Extracted the shared lookup into assetLocaleGetStringLookup and added a dedicated assetLocaleGetHeader for that internal read, leaving assetLocaleGetString's validation untouched for every real caller. Also replaced every raw assetLocaleGetString/WithVA call across the UI with the locale/localemanager.h helpers (adding localeManagerGetString for the plain, non-formatting case), so app code no longer bypasses them. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
1 parent
5b523c68a7
commit
f63653c307
21 files changed
+353
-138
No files matched your search
@@ -30,8 +30,8 @@ errorret_t assetLocaleLoaderAsync(assetloading_t *loading) {
|
||||
assetLoaderErrorChain(loading, assetFileOpen(&localeFile->file));
|
||||
|
||||
char_t buffer[1024];
|
||||
assetLoaderErrorChain(loading, assetLocaleGetString(
|
||||
localeFile, "", 0, buffer, sizeof(buffer)
|
||||
assetLoaderErrorChain(loading, assetLocaleGetHeader(
|
||||
localeFile, buffer, sizeof(buffer)
|
||||
));
|
||||
assetLoaderErrorChain(loading, assetLocaleParseHeader(
|
||||
localeFile, buffer, sizeof(buffer)
|
||||
@@ -487,6 +487,7 @@ errorret_t assetLocaleCacheFind(
|
||||
assertNotNull(file, "Asset file cannot be NULL.");
|
||||
assertNotNull(messageId, "Message ID cannot be NULL.");
|
||||
assertNotNull(outHit, "outHit cannot be NULL.");
|
||||
assertStrLenMin(messageId, 1, "Message ID cannot be empty.");
|
||||
|
||||
*outHit = false;
|
||||
if(file->cache == NULL) errorOk();
|
||||
@@ -527,6 +528,7 @@ void assetLocaleCacheInsert(
|
||||
assertNotNull(file, "Asset file cannot be NULL.");
|
||||
assertNotNull(messageId, "Message ID cannot be NULL.");
|
||||
assertNotNull(value, "Value cannot be NULL.");
|
||||
assertStrLenMin(messageId, 1, "Message ID cannot be empty.");
|
||||
|
||||
// Caching is a pure optimization - a message ID or value too long for a
|
||||
// fixed cache slot is just never cached, not an error.
|
||||
@@ -555,7 +557,13 @@ void assetLocaleCacheInsert(
|
||||
stringCopy(entry->value, value, ASSET_LOCALE_CACHE_VALUE_MAX);
|
||||
}
|
||||
|
||||
errorret_t assetLocaleGetString(
|
||||
// Shared by assetLocaleGetString (external callers, messageId required
|
||||
// non-empty) and assetLocaleGetHeader (messageId "", the PO format's own
|
||||
// sentinel for its header entry - see assetLocaleGetHeader). Caching is
|
||||
// skipped entirely for an empty messageId: assetLocaleCacheFind/Insert
|
||||
// both reject one outright (same guard as assetLocaleGetString's own),
|
||||
// and it's a one-shot boot-time read anyway, not worth caching.
|
||||
errorret_t assetLocaleGetStringLookup(
|
||||
assetlocalefile_t *file,
|
||||
const char_t *messageId,
|
||||
const int32_t pluralCount,
|
||||
@@ -569,10 +577,12 @@ errorret_t assetLocaleGetString(
|
||||
assertTrue(stringBufferSize > 0, "String buffer size must be > 0");
|
||||
|
||||
bool_t cacheHit = false;
|
||||
errorChain(assetLocaleCacheFind(
|
||||
file, messageId, pluralCount, stringBuffer, stringBufferSize, &cacheHit
|
||||
));
|
||||
if(cacheHit) errorOk();
|
||||
if(messageId[0] != '\0') {
|
||||
errorChain(assetLocaleCacheFind(
|
||||
file, messageId, pluralCount, stringBuffer, stringBufferSize, &cacheHit
|
||||
));
|
||||
if(cacheHit) errorOk();
|
||||
}
|
||||
|
||||
assetfilelinereader_t reader;
|
||||
|
||||
@@ -717,11 +727,38 @@ errorret_t assetLocaleGetString(
|
||||
errorThrow("Failed to find msgstr for message ID: %s", messageId);
|
||||
}
|
||||
|
||||
assetLocaleCacheInsert(file, messageId, pluralCount, stringBuffer);
|
||||
if(messageId[0] != '\0') {
|
||||
assetLocaleCacheInsert(file, messageId, pluralCount, stringBuffer);
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t assetLocaleGetString(
|
||||
assetlocalefile_t *file,
|
||||
const char_t *messageId,
|
||||
const int32_t pluralCount,
|
||||
char_t *stringBuffer,
|
||||
const size_t stringBufferSize
|
||||
) {
|
||||
assertNotNull(messageId, "Message ID cannot be NULL.");
|
||||
assertStrLenMin(messageId, 1, "Message ID cannot be empty.");
|
||||
|
||||
return assetLocaleGetStringLookup(
|
||||
file, messageId, pluralCount, stringBuffer, stringBufferSize
|
||||
);
|
||||
}
|
||||
|
||||
errorret_t assetLocaleGetHeader(
|
||||
assetlocalefile_t *file,
|
||||
char_t *stringBuffer,
|
||||
const size_t stringBufferSize
|
||||
) {
|
||||
return assetLocaleGetStringLookup(
|
||||
file, "", 0, stringBuffer, stringBufferSize
|
||||
);
|
||||
}
|
||||
|
||||
errorret_t assetLocaleGetStringWithVA(
|
||||
assetlocalefile_t *file,
|
||||
const char_t *messageId,
|
||||
|
||||
Reference in new issue
Block a user