Load the menu's zstd dictionaries once behind a once-guard, so a second thread asking during the load waits instead of finding none.

The loader set the count to 0 before it read the file; the menu-art thread and the present path both ask in the first frames, and the one that lost took 0 for "no dictionaries" and kept the fallback fonts for the whole run.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-10 23:27:51 -05:00
parent 3e67a74cfc
commit 7966181115

View File

@@ -20,6 +20,7 @@
#include "host.h"
#include "menu_assets.h"
#include "tex.h"
#include "platform/platform.h"
#define MAX_RAW (512u << 20)
@@ -52,7 +53,8 @@ static ZSTD_DDict *dicts[8];
static unsigned dict_ids[8];
static int ndicts = -1;
static void dicts_load(void) {
static void dicts_read(void *unused) {
(void)unused;
ndicts = 0;
size_t zn = 0;
uint64_t zn64 = 0;
@@ -76,6 +78,14 @@ static void dicts_load(void) {
free(z);
}
// Once, whichever thread asks first (the "menu-art" thread and the present path both do in the first frames); the
// others wait for it. Checking ndicts < 0 instead let a second caller see the 0 set at the start of the read, take it
// for "no dictionaries" and fail its asset: the menu then kept its fallback fonts for the whole run.
static void dicts_load(void) {
static PlatOnce once = PLAT_ONCE_INIT;
plat_once(&once, dicts_read, NULL);
}
uint8_t *menu_asset_load(const char *rel, size_t *n_out) {
uint64_t n = 0;
uint8_t *b = romfs_load(rel, &n);
@@ -89,7 +99,7 @@ uint8_t *menu_asset_load(const char *rel, size_t *n_out) {
if (rn == ZSTD_CONTENTSIZE_UNKNOWN) { // a frame that does not say its size: streamed into a growing buffer
ZSTD_DDict *d = NULL;
if (id) {
if (ndicts < 0) dicts_load();
dicts_load();
for (int i = 0; i < ndicts; i++)
if (dict_ids[i] == id) d = dicts[i];
if (!d) { free(b); return NULL; }
@@ -122,7 +132,7 @@ uint8_t *menu_asset_load(const char *rel, size_t *n_out) {
size_t got = 0;
if (raw) {
if (id) {
if (ndicts < 0) dicts_load();
dicts_load();
ZSTD_DDict *d = NULL;
for (int i = 0; i < ndicts; i++)
if (dict_ids[i] == id) d = dicts[i];