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)