mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -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 );
|
TerrainAtlas1D.UpdateState( TerrainAtlas );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChangeTerrainAtlas( Bitmap newAtlas ) {
|
public bool ChangeTerrainAtlas( Bitmap atlas ) {
|
||||||
LoadAtlas( newAtlas );
|
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();
|
Events.RaiseTerrainAtlasChanged();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run() { window.Run(); }
|
public void Run() { window.Run(); }
|
||||||
|
@ -134,7 +134,7 @@ namespace ClassicalSharp {
|
|||||||
Utils.LogDebug( "Converting terrain atlas to 32bpp image" );
|
Utils.LogDebug( "Converting terrain atlas to 32bpp image" );
|
||||||
game.Drawer2D.ConvertTo32Bpp( ref bmp );
|
game.Drawer2D.ConvertTo32Bpp( ref bmp );
|
||||||
}
|
}
|
||||||
game.ChangeTerrainAtlas( bmp );
|
if( !game.ChangeTerrainAtlas( bmp ) ) { bmp.Dispose(); return; }
|
||||||
TextureCache.AddToCache( item.Url, bmp );
|
TextureCache.AddToCache( item.Url, bmp );
|
||||||
TextureCache.AddETagToCache( item.Url, item.ETag, game.ETags );
|
TextureCache.AddETagToCache( item.Url, item.ETag, game.ETags );
|
||||||
} else if( Is304Status( item.WebEx ) ) {
|
} else if( Is304Status( item.WebEx ) ) {
|
||||||
@ -143,7 +143,7 @@ namespace ClassicalSharp {
|
|||||||
ExtractDefault();
|
ExtractDefault();
|
||||||
} else if( item.Url != game.World.TextureUrl ) {
|
} else if( item.Url != game.World.TextureUrl ) {
|
||||||
game.Animations.Dispose();
|
game.Animations.Dispose();
|
||||||
game.ChangeTerrainAtlas( bmp );
|
if( !game.ChangeTerrainAtlas( bmp ) ) { bmp.Dispose(); return; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if( bmp != null ) game.World.TextureUrl = item.Url;
|
if( bmp != null ) game.World.TextureUrl = item.Url;
|
||||||
|
@ -36,7 +36,7 @@ namespace ClassicalSharp.TexturePack {
|
|||||||
if( animations.Count == 0 ) return;
|
if( animations.Count == 0 ) return;
|
||||||
if( fastBmp == null ) {
|
if( fastBmp == null ) {
|
||||||
game.Chat.Add( "&cCurrent texture pack specifies it uses animations," );
|
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();
|
animations.Clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,9 @@ namespace ClassicalSharp.TexturePack {
|
|||||||
|
|
||||||
switch( filename ) {
|
switch( filename ) {
|
||||||
case "terrain.png":
|
case "terrain.png":
|
||||||
game.ChangeTerrainAtlas( Platform.ReadBmp( stream ) ); break;
|
Bitmap atlas = Platform.ReadBmp( stream );
|
||||||
|
if( !game.ChangeTerrainAtlas( atlas ) ) atlas.Dispose();
|
||||||
|
break;
|
||||||
case "chicken.png":
|
case "chicken.png":
|
||||||
UpdateTexture( ref cache.ChickenTexId, stream, false ); break;
|
UpdateTexture( ref cache.ChickenTexId, stream, false ); break;
|
||||||
case "creeper.png":
|
case "creeper.png":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user