mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
Reject invalid terrain.png (non square, non power of 2) instead of crashing. (Thanks 123DMWM)
This commit is contained in:
parent
ca0b9cc038
commit
f63ca316d7
@ -34,9 +34,16 @@ namespace ClassicalSharp {
|
||||
TerrainAtlas1D.UpdateState( TerrainAtlas );
|
||||
}
|
||||
|
||||
public void ChangeTerrainAtlas( Bitmap newAtlas ) {
|
||||
LoadAtlas( newAtlas );
|
||||
public bool ChangeTerrainAtlas( Bitmap atlas ) {
|
||||
bool pow2 = Utils.IsPowerOf2( atlas.Width ) && Utils.IsPowerOf2( atlas.Height );
|
||||
if( !pow2 || atlas.Width != atlas.Height ) {
|
||||
Chat.Add( "&cCurrent texture pack has an invalid terrain.png" );
|
||||
Chat.Add( "&cWidth and length must be the same, and also powers of two." );
|
||||
return false;
|
||||
}
|
||||
LoadAtlas( atlas );
|
||||
Events.RaiseTerrainAtlasChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Run() { window.Run(); }
|
||||
|
@ -134,7 +134,7 @@ namespace ClassicalSharp {
|
||||
Utils.LogDebug( "Converting terrain atlas to 32bpp image" );
|
||||
game.Drawer2D.ConvertTo32Bpp( ref bmp );
|
||||
}
|
||||
game.ChangeTerrainAtlas( bmp );
|
||||
if( !game.ChangeTerrainAtlas( bmp ) ) { bmp.Dispose(); return; }
|
||||
TextureCache.AddToCache( item.Url, bmp );
|
||||
TextureCache.AddETagToCache( item.Url, item.ETag, game.ETags );
|
||||
} else if( Is304Status( item.WebEx ) ) {
|
||||
@ -143,7 +143,7 @@ namespace ClassicalSharp {
|
||||
ExtractDefault();
|
||||
} else if( item.Url != game.World.TextureUrl ) {
|
||||
game.Animations.Dispose();
|
||||
game.ChangeTerrainAtlas( bmp );
|
||||
if( !game.ChangeTerrainAtlas( bmp ) ) { bmp.Dispose(); return; }
|
||||
}
|
||||
|
||||
if( bmp != null ) game.World.TextureUrl = item.Url;
|
||||
|
@ -36,7 +36,7 @@ namespace ClassicalSharp.TexturePack {
|
||||
if( animations.Count == 0 ) return;
|
||||
if( fastBmp == null ) {
|
||||
game.Chat.Add( "&cCurrent texture pack specifies it uses animations," );
|
||||
game.Chat.Add( "&cbut it is missing animations.png");
|
||||
game.Chat.Add( "&cbut is missing animations.png" );
|
||||
animations.Clear();
|
||||
return;
|
||||
}
|
||||
|
@ -43,7 +43,9 @@ namespace ClassicalSharp.TexturePack {
|
||||
|
||||
switch( filename ) {
|
||||
case "terrain.png":
|
||||
game.ChangeTerrainAtlas( Platform.ReadBmp( stream ) ); break;
|
||||
Bitmap atlas = Platform.ReadBmp( stream );
|
||||
if( !game.ChangeTerrainAtlas( atlas ) ) atlas.Dispose();
|
||||
break;
|
||||
case "chicken.png":
|
||||
UpdateTexture( ref cache.ChickenTexId, stream, false ); break;
|
||||
case "creeper.png":
|
||||
|
Loading…
x
Reference in New Issue
Block a user