Skip to content

Commit 53945f2

Browse files
committed
Memory management optimization for streamer/texture loading
1 parent b2b8001 commit 53945f2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Client/game_sa/CRenderWareSA.TextureReplacing.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,29 @@ bool CRenderWareSA::ModelInfoTXDAddTextures(SReplacementTextures* pReplacementTe
263263
perTxdInfo.usingTextures.push_back(pNewTexture);
264264
}
265265

266+
// Request space from the SA streaming system for the new textures.
267+
// This reduces mem pressure/OOM by encouraging the engine to free unused resources.
268+
// Note: We do not modify CStreamingInfo::sizeInBlocks as that affects disk I/O during model reload.
269+
// Only perform this check for new rasters (not copies) to avoid double-counting shared resources.
270+
if (!perTxdInfo.bTexturesAreCopies && pGame->GetStreaming())
271+
{
272+
uint32_t uiTotalSize = 0;
273+
for (RwTexture* pNewTexture : perTxdInfo.usingTextures)
274+
{
275+
if (pNewTexture && SharedUtil::IsReadablePointer(pNewTexture, sizeof(RwTexture)) && pNewTexture->raster)
276+
{
277+
// Estimate texture size (Width * Height * 4 bytes for 32-bit).
278+
// This helps the SA streaming system manage memory pressure.
279+
uiTotalSize += pNewTexture->raster->width * pNewTexture->raster->height * 4;
280+
}
281+
}
282+
283+
if (uiTotalSize > 0)
284+
{
285+
pGame->GetStreaming()->MakeSpaceFor(uiTotalSize);
286+
}
287+
}
288+
266289
//
267290
// Add each texture to the target txd
268291
//

0 commit comments

Comments
 (0)