From 07557fe06caf889ce6d86f3388454943eab799b0 Mon Sep 17 00:00:00 2001 From: chrg6 Date: Thu, 12 Nov 2026 15:31:25 -0500 Subject: [PATCH] Give an empty slot's handle for a texture id out of range instead of ending the game. nvnDeviceGetTextureHandle ended the game when the texture id was negative or past the table. The game passes -1 when it has no texture to give, as when its render-target heap is full; the handle of the last slot, which no game registers, draws the stand-in like any slot without a texture. Logged up to eight times. Co-Authored-By: Claude Fable 5.2 --- runtime/nvn_api_core.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/runtime/nvn_api_core.c b/runtime/nvn_api_core.c index 3945b419..caad7a04 100644 --- a/runtime/nvn_api_core.c +++ b/runtime/nvn_api_core.c @@ -236,9 +236,19 @@ NVN_API(nvnDeviceRegisterFastClearDepth) { ret_x(c, 0); } NVN_API(nvnDeviceGetImageHandle) { ret_x(c, (uint64_t)(int64_t)(int)arg_x(c, 1)); } // NVNtextureHandle nvnDeviceGetTextureHandle(const NVNdevice *d, int texture_id, int sampler_id): // texture id (20 bits) | sampler id << 20, the encoding the replay decodes (NVN_HANDLE_TEX / NVN_HANDLE_SAMP) +// An id out of range (-1: the game had no texture to give, as when its render-target heap is full) gets the handle of +// the last texture slot, which no game registers (its pool has 32,768), so a draw through it samples the stand-in as +// for any slot without a texture, and sampler 0. Ending the game here turned one missing texture into a crash. NVN_API(nvnDeviceGetTextureHandle) { int tid = (int)arg_x(c, 1), sid = (int)arg_x(c, 2); - if (tid < 0 || tid >= (1 << 20) || sid < 0 || sid >= (1 << 12)) rt_fatal("nvn: texture handle ids out of range %d/%d", tid, sid); + if (tid < 0 || tid >= (1 << 20) || sid < 0 || sid >= (1 << 12)) { + static int said; + if (said < 8 && ++said) + rt_log("nvn: texture handle asked for with ids out of range (texture %d, sampler %d): the handle of an " + "empty slot is given, which draws the stand-in", tid, sid); + if (tid < 0 || tid >= (1 << 20)) tid = (1 << 20) - 1; + if (sid < 0 || sid >= (1 << 12)) sid = 0; + } ret_x(c, (uint64_t)tid | (uint64_t)sid << 20); } // NVNtextureHandle nvnDeviceGetTexelFetchHandle(const NVNdevice *d, int texture_id)