Skip to content

Commit 1c4c96a

Browse files
committed
Clean up RE_GenerateTexture
Fixes #271.
1 parent ce01998 commit 1c4c96a

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/engine/client/cl_cgame.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,12 @@ void CGameVM::QVMSyscall(int syscallNum, Util::Reader& reader, IPC::Channel& cha
13581358

13591359
case CG_R_GENERATETEXTURE:
13601360
IPC::HandleMsg<Render::GenerateTextureMsg>(channel, std::move(reader), [this] (std::vector<byte> data, int x, int y, qhandle_t& handle) {
1361+
// Limit max size to avoid int overflow issues
1362+
if (x <= 0 || y <= 0 || x > 16384 || y > 16384 || size_t(x * y * 4) != data.size()) {
1363+
Log::Warn("GenerateTextureMsg: bad dimensions or size: %dx%d / %d bytes", x, y, data.size());
1364+
handle = 0;
1365+
return;
1366+
}
13611367
handle = re.GenerateTexture(data.data(), x, y);
13621368
});
13631369
break;

src/engine/renderer/tr_image.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3184,26 +3184,18 @@ void RE_GetTextureSize( int textureID, int *width, int *height )
31843184
}
31853185
}
31863186

3187-
// This code is used to upload images produced by the game (like GUI elements produced by libRocket in Unvanquished)
3188-
int numTextures = 0;
3189-
3187+
// This code is used to upload images produced by the game (like glyphs produced by RMLUI in Unvanquished)
31903188
qhandle_t RE_GenerateTexture( const byte *pic, int width, int height )
31913189
{
3192-
size_t size = width * height;
3193-
3194-
if ( !size ) {
3195-
Log::Warn("RE_GenerateTexture: image size %dx%d is 0", width, height );
3196-
return 0;
3197-
}
3198-
31993190
R_SyncRenderThread();
32003191

3201-
const char *name = va( "rocket%d", numTextures++ );
3192+
std::string name = Str::Format( "$generatedTexture%d", tr.numGeneratedTextures++ );
32023193

32033194
imageParams_t imageParams = {};
32043195
imageParams.bits = IF_NOPICMIP;
32053196
imageParams.filterType = filterType_t::FT_LINEAR;
32063197
imageParams.wrapType = wrapTypeEnum_t::WT_CLAMP;
32073198

3208-
return RE_RegisterShaderFromImage( name, R_CreateImage( name, &pic, width, height, 1, imageParams ) );
3199+
return RE_RegisterShaderFromImage(
3200+
name.c_str(), R_CreateImage( name.c_str(), &pic, width, height, 1, imageParams ) );
32093201
}

src/engine/renderer/tr_local.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,6 +2849,8 @@ enum class ssaoMode {
28492849

28502850
std::vector<image_t *> images;
28512851

2852+
unsigned numGeneratedTextures;
2853+
28522854
int numFBOs;
28532855
FBO_t *fbos[ MAX_FBOS ];
28542856

0 commit comments

Comments
 (0)