Don't crash on too large skins

This commit is contained in:
UnknownShadow200 2018-11-25 15:31:40 +11:00
parent 4205775f38
commit 6a03660fb2
2 changed files with 8 additions and 10 deletions

View File

@ -134,9 +134,9 @@ namespace ClassicalSharp.Entities {
EnsurePow2(ref bmp);
SkinType = Utils.GetSkinType(bmp);
if (SkinType == SkinType.Invalid) {
SetSkinAll(true);
} else {
if (bmp.Width > game.Graphics.MaxTexWidth || bmp.Height > game.Graphics.MaxTexHeight) {
game.Chat.Add("&cSkin " + SkinName + " is too large");
} else if (SkinType != SkinType.Invalid) {
if (Model.UsesHumanSkin) ClearHat(bmp, SkinType);
TextureId = game.Graphics.CreateTexture(bmp, true, false);
SetSkinAll(false);

View File

@ -715,7 +715,7 @@ static void Player_CheckSkin(struct Player* p) {
}
p->FetchedSkin = true;
}
if (!AsyncDownloader_Get(&skin, &item)) return;
if (!item.ResultData) { Player_SetSkinAll(p, true); return; }
Stream_ReadonlyMemory(&mem, item.ResultData, item.ResultSize);
@ -731,12 +731,10 @@ static void Player_CheckSkin(struct Player* p) {
Player_EnsurePow2(p, &bmp);
e->SkinType = Utils_GetSkinType(&bmp);
if (e->SkinType == SKIN_INVALID) {
Player_SetSkinAll(p, true);
} else {
if (e->Model->UsesHumanSkin) {
Player_ClearHat(&bmp, e->SkinType);
}
if (bmp.Width > Gfx_MaxTexWidth || bmp.Height > Gfx_MaxTexHeight) {
Chat_Add1("&cSkin %s is too large", &skin);
} else if (e->SkinType != SKIN_INVALID) {
if (e->Model->UsesHumanSkin) Player_ClearHat(&bmp, e->SkinType);
e->TextureId = Gfx_CreateTexture(&bmp, true, false);
Player_SetSkinAll(p, false);
}