Don't divide by 0 in LoadSkin

src/game/client/components/skins.cpp:142:14: runtime error: -nan is outside the range of representable values of type 'int'
    #0 0x55b6bd0f49e1 in CSkins::LoadSkin(char const*, char const*, int, int*) /media/ddnet/src/game/client/components/skins.cpp:142:14
    #1 0x55b6bd0f0942 in CSkins::SkinScan(char const*, int, int, void*) /media/ddnet/src/game/client/components/skins.cpp:55:16
    #2 0x55b6bcb33928 in fs_listdir /media/ddnet/src/base/system.c:2033:6
    #3 0x55b6bcb04024 in CStorage::ListDirectory(int, char const*, int (*)(char const*, int, int, void*), void*) /media/ddnet/src/engine/shared/storage.cpp:316:5
    #4 0x55b6bd0f9e2f in CSkins::Refresh() /media/ddnet/src/game/client/components/skins.cpp:222:13
    #5 0x55b6bd0f6e33 in CSkins::OnInit() /media/ddnet/src/game/client/components/skins.cpp:194:2
    #6 0x55b6bd14c63f in CGameClient::OnInit() /media/ddnet/src/game/client/gameclient.cpp:322:28
    #7 0x55b6bcc5f9f8 in CClient::Run() /media/ddnet/src/engine/client/client.cpp:3089:16
    #8 0x55b6bcc84b7e in main /media/ddnet/src/engine/client/client.cpp:4341:11
    #9 0x7f1144ded151 in __libc_start_main (/usr/lib/libc.so.6+0x28151)
    #10 0x55b6bc9d1e0d in _start (/media/ddnet/DDNet+0x705e0d)
This commit is contained in:
def 2020-10-10 12:14:07 +02:00
parent a83b7b0733
commit f94d476cf2

View file

@ -138,8 +138,12 @@ int CSkins::LoadSkin(const char *pName, const char *pPath, int DirType, int *pGe
for(int x = 0; x < BodySize; x++)
{
int v = d[y * Pitch + x * 4];
if(v <= OrgWeight)
if(OrgWeight == 0)
v = 0;
else if(v <= OrgWeight)
v = (int)(((v / (float)OrgWeight) * NewWeight));
else if(InvOrgWeight == 0)
v = NewWeight;
else
v = (int)(((v - OrgWeight) / (float)InvOrgWeight) * InvNewWeight + NewWeight);
d[y * Pitch + x * 4] = v;