From c010b1ffee72bb679b4420bf94434a1736563684 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Fri, 24 May 2024 17:09:38 -0500 Subject: [PATCH] Fix reading source in levelshot command Fix using offset for source returned by RB_ReadPixels(). In practice this shouldn't be an issue because Hunk_AllocateTempMemory() should already be aligned to sizeof(intptr_t). --- code/renderergl1/tr_init.c | 7 ++++--- code/renderergl2/tr_init.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/code/renderergl1/tr_init.c b/code/renderergl1/tr_init.c index be88daff..425f84ae 100644 --- a/code/renderergl1/tr_init.c +++ b/code/renderergl1/tr_init.c @@ -531,7 +531,7 @@ the menu system, sampled down from full screen distorted images */ void R_LevelShot( screenshotType_e type, const char *ext ) { char fileName[MAX_OSPATH]; - byte *source; + byte *source, *allsource; byte *resample, *resamplestart; size_t offset = 0, memcount; int spadlen, rpadlen; @@ -559,7 +559,8 @@ void R_LevelShot( screenshotType_e type, const char *ext ) { Com_sprintf(fileName, sizeof(fileName), "levelshots/%s%s", tr.world->baseName, ext); - source = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &spadlen); + allsource = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &spadlen); + source = allsource + offset; // // Based on RB_ReadPixels @@ -613,7 +614,7 @@ void R_LevelShot( screenshotType_e type, const char *ext ) { RE_SavePNG(fileName, width, height, resample + offset, rpadlen); ri.Hunk_FreeTempMemory(resample); - ri.Hunk_FreeTempMemory(source); + ri.Hunk_FreeTempMemory(allsource); ri.Printf( PRINT_ALL, "Wrote %s\n", fileName ); } diff --git a/code/renderergl2/tr_init.c b/code/renderergl2/tr_init.c index 5b00dd76..b4a57af7 100644 --- a/code/renderergl2/tr_init.c +++ b/code/renderergl2/tr_init.c @@ -622,7 +622,7 @@ the menu system, sampled down from full screen distorted images */ void R_LevelShot( screenshotType_e type, const char *ext ) { char fileName[MAX_OSPATH]; - byte *source; + byte *source, *allsource; byte *resample, *resamplestart; size_t offset = 0, memcount; int spadlen, rpadlen; @@ -650,7 +650,8 @@ void R_LevelShot( screenshotType_e type, const char *ext ) { Com_sprintf(fileName, sizeof(fileName), "levelshots/%s%s", tr.world->baseName, ext); - source = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &spadlen); + allsource = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &spadlen); + source = allsource + offset; // // Based on RB_ReadPixels @@ -704,7 +705,7 @@ void R_LevelShot( screenshotType_e type, const char *ext ) { RE_SavePNG(fileName, width, height, resample + offset, rpadlen); ri.Hunk_FreeTempMemory(resample); - ri.Hunk_FreeTempMemory(source); + ri.Hunk_FreeTempMemory(allsource); ri.Printf( PRINT_ALL, "Wrote %s\n", fileName ); }