Skip to content

Commit

Permalink
Actual fix for crash with RGB images, convert them to RGBA instead
Browse files Browse the repository at this point in the history
  • Loading branch information
def- committed Apr 4, 2015
1 parent 9c05803 commit 0945e24
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/game/editor/io.cpp
Expand Up @@ -282,9 +282,23 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
else else
{ {
if(pImg->m_Format == CImageInfo::FORMAT_RGB) if(pImg->m_Format == CImageInfo::FORMAT_RGB)
Item.m_ImageData = df.AddData(Item.m_Width*Item.m_Height*3, pImg->m_pData); {
// Convert to RGBA
unsigned char *pData = (unsigned char*) mem_alloc(Item.m_Width*Item.m_Height*4, 1);
for(int i = 0; i < Item.m_Width*Item.m_Height; i++)
{
pData[i*4] = ((unsigned char*)(pImg->m_pData))[i*3];
pData[i*4+1] = ((unsigned char*)(pImg->m_pData))[i*3+1];
pData[i*4+2] = ((unsigned char*)(pImg->m_pData))[i*3+2];
pData[i*4+3] = 255;
}
Item.m_ImageData = df.AddData(Item.m_Width*Item.m_Height*4, pData);
mem_free(pData);
}
else else
{
Item.m_ImageData = df.AddData(Item.m_Width*Item.m_Height*4, pImg->m_pData); Item.m_ImageData = df.AddData(Item.m_Width*Item.m_Height*4, pImg->m_pData);
}
} }
df.AddItem(MAPITEMTYPE_IMAGE, i, sizeof(Item), &Item); df.AddItem(MAPITEMTYPE_IMAGE, i, sizeof(Item), &Item);
} }
Expand Down

0 comments on commit 0945e24

Please sign in to comment.