Skip to content

Commit b96eefc

Browse files
committed
fix(SaveTexture): use a different approach to avoid a memory issue
1 parent 70ce28b commit b96eefc

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

cmp_framework/compute_base.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -867,23 +867,20 @@ static CMP_ERROR SaveTextureViaMipSet(const char* destFile, CMP_Texture* pTextur
867867

868868
if (pMipLevel)
869869
{
870-
// Free the originally allocated data since we don't need it
871-
if (pMipLevel->m_pbData)
872-
{
873-
free(pMipLevel->m_pbData);
874-
}
870+
// Store the original allocated pointer to restore it later
871+
CMP_BYTE* originalData = pMipLevel->m_pbData;
875872

876-
// Update pointers
873+
// Point to the texture's data instead of copying
877874
pMipLevel->m_pbData = pTexture->pData;
878875
pMipLevel->m_dwLinearSize = pTexture->dwDataSize;
879876
tempMipSet.pData = pTexture->pData;
880877
tempMipSet.dwDataSize = pTexture->dwDataSize;
881878

882879
result = CMP_SaveTexture(destFile, &tempMipSet);
883880

884-
// The texture we passed in, could still be needed, we don't want the mipset to free its data when we free it.
885-
pMipLevel->m_pbData = NULL;
886-
tempMipSet.pData = NULL;
881+
// Restore the original pointer before cleanup so FreeMipSet can clean it up properly
882+
pMipLevel->m_pbData = originalData;
883+
tempMipSet.pData = originalData;
887884
}
888885
else
889886
{

0 commit comments

Comments
 (0)