Reset texture ids to -1 in DeleteTexture().

This commit is contained in:
UnknownShadow200 2015-05-14 06:40:33 +10:00
parent 714f03e893
commit bc77db70e3
18 changed files with 32 additions and 40 deletions

View File

@ -110,7 +110,7 @@ namespace ClassicalSharp {
Window.AsyncDownloader.TryGetItem( "skin_" + SkinName, out item );
if( item != null && item.Bmp != null ) {
Bitmap bmp = item.Bmp;
Window.Graphics.DeleteTexture( renderer.TextureId );
Window.Graphics.DeleteTexture( ref renderer.TextureId );
renderer.TextureId = Window.Graphics.LoadTexture( bmp );
SkinType = Utils.GetSkinType( bmp );
bmp.Dispose();

View File

@ -96,12 +96,10 @@ namespace ClassicalSharp {
void LoadAtlas( Bitmap bmp ) {
// Cleanup old atlas if applicable.
if( TerrainAtlasTexId != -1 ) {
Graphics.DeleteTexture( TerrainAtlasTexId );
}
Graphics.DeleteTexture( ref TerrainAtlasTexId );
if( TerrainAtlas1DTexIds != null ) {
for( int i = 0; i < TerrainAtlas1DTexIds.Length; i++ ) {
Graphics.DeleteTexture( TerrainAtlas1DTexIds[i] );
Graphics.DeleteTexture( ref TerrainAtlas1DTexIds[i] );
}
}
if( TerrainAtlas != null ) {
@ -303,9 +301,9 @@ namespace ClassicalSharp {
SetNewScreen( null );
fpsScreen.Dispose();
SelectionManager.Dispose();
Graphics.DeleteTexture( TerrainAtlasTexId );
Graphics.DeleteTexture( ref TerrainAtlasTexId );
for( int i = 0; i < TerrainAtlas1DTexIds.Length; i++ ) {
Graphics.DeleteTexture( TerrainAtlas1DTexIds[i] );
Graphics.DeleteTexture( ref TerrainAtlas1DTexIds[i] );
}
ModelCache.Dispose();
for( int i = 0; i < NetPlayers.Length; i++ ) {

View File

@ -34,11 +34,10 @@ namespace ClassicalSharp.GraphicsAPI {
public abstract void Bind2DTexture( int texId );
public abstract void DeleteTexture( int texId );
public abstract void DeleteTexture( ref int texId );
public virtual void DeleteTexture( ref Texture texture ) {
DeleteTexture( texture.ID );
texture.ID = 0;
DeleteTexture( ref texture.ID );
}

View File

@ -156,12 +156,13 @@ namespace ClassicalSharp.GraphicsAPI {
GL.BindTexture( TextureTarget.Texture2D, texture );
}
public override void DeleteTexture( int texId ) {
public override void DeleteTexture( ref int texId ) {
if( texId <= 0 ) return;
#if TRACK_RESOURCES
textures.Remove( texId );
#endif
GL.DeleteTexture( texId );
texId = -1;
}
public override bool Texturing {

View File

@ -33,15 +33,9 @@ namespace Launcher {
form.Text = MainForm.AppName + " - fetching " + output;
try {
byte[] data = client.DownloadData( resUri + uri );
try {
File.WriteAllBytes( output, data );
} catch( IOException ) {
MessageBox.Show( "Unable to save " + output, "Failed to save resource", MessageBoxButtons.OK, MessageBoxIcon.Error );
return false;
}
client.DownloadFile( resUri + uri, output );
} catch( WebException ) {
MessageBox.Show( "Unable to download " + output, "Failed to download resource", MessageBoxButtons.OK, MessageBoxIcon.Error );
MessageBox.Show( "Unable to download or save " + output, "Failed to download or save resource", MessageBoxButtons.OK, MessageBoxIcon.Error );
return false;
}
return true;

View File

@ -75,7 +75,7 @@ namespace ClassicalSharp.Model {
public override void Dispose() {
Set.Dispose();
graphics.DeleteTexture( DefaultSkinTextureId );
graphics.DeleteTexture( ref DefaultSkinTextureId );
}
class ModelSet {

View File

@ -55,7 +55,7 @@ namespace ClassicalSharp.Model {
public override void Dispose() {
Set.Dispose();
graphics.DeleteTexture( DefaultSkinTextureId );
graphics.DeleteTexture( ref DefaultSkinTextureId );
}
class ModelSet {

View File

@ -55,7 +55,7 @@ namespace ClassicalSharp.Model {
public override void Dispose() {
Set.Dispose();
graphics.DeleteTexture( DefaultSkinTextureId );
graphics.DeleteTexture( ref DefaultSkinTextureId );
}
class ModelSet {

View File

@ -101,7 +101,7 @@ namespace ClassicalSharp.Model {
Set64x32.Dispose();
Set64x64.Dispose();
Set64x64Slim.Dispose();
graphics.DeleteTexture( DefaultSkinTextureId );
graphics.DeleteTexture( ref DefaultSkinTextureId );
}
class ModelSet {

View File

@ -88,9 +88,9 @@ namespace ClassicalSharp.Model {
public override void Dispose() {
Set.Dispose();
graphics.DeleteTexture( DefaultSkinTextureId );
graphics.DeleteTexture( ref DefaultSkinTextureId );
if( Fur ) {
graphics.DeleteTexture( furTextureId );
graphics.DeleteTexture( ref furTextureId );
}
}

View File

@ -67,7 +67,7 @@ namespace ClassicalSharp.Model {
public override void Dispose() {
Set.Dispose();
graphics.DeleteTexture( DefaultSkinTextureId );
graphics.DeleteTexture( ref DefaultSkinTextureId );
}
class ModelSet {

View File

@ -63,7 +63,7 @@ namespace ClassicalSharp.Model {
public override void Dispose() {
Set.Dispose();
graphics.DeleteTexture( DefaultSkinTextureId );
graphics.DeleteTexture( ref DefaultSkinTextureId );
}
class ModelSet {

View File

@ -67,7 +67,7 @@ namespace ClassicalSharp.Model {
public override void Dispose() {
Set.Dispose();
graphics.DeleteTexture( DefaultSkinTextureId );
graphics.DeleteTexture( ref DefaultSkinTextureId );
}
class ModelSet {

View File

@ -80,7 +80,7 @@ namespace ClassicalSharp.Renderers {
base.Dispose();
Graphics.DeleteVb( skyVbo );
Graphics.DeleteVb( cloudsVbo );
Graphics.DeleteTexture( cloudTexture );
Graphics.DeleteTexture( ref cloudTexture );
}
void RenderClouds( double delta ) {

View File

@ -118,8 +118,8 @@ namespace ClassicalSharp {
public override void Dispose() {
base.Dispose();
index = 0;
Graphics.DeleteTexture( edgeTexId );
Graphics.DeleteTexture( sideTexId );
Graphics.DeleteTexture( ref edgeTexId );
Graphics.DeleteTexture( ref sideTexId );
Graphics.DeleteVb( sidesVboId );
Graphics.DeleteVb( edgesVboId );
sidesVboId = edgesVboId = -1;
@ -140,13 +140,13 @@ namespace ClassicalSharp {
void MakeEdgeTexture() {
int texLoc = Window.BlockInfo.GetOptimTextureLoc( (byte)Map.EdgeBlock, TileSide.Top );
Window.Graphics.DeleteTexture( edgeTexId );
Window.Graphics.DeleteTexture( ref edgeTexId );
edgeTexId = Window.TerrainAtlas.LoadTextureElement( texLoc );
}
void MakeSideTexture() {
int texLoc = Window.BlockInfo.GetOptimTextureLoc( (byte)Map.SidesBlock, TileSide.Top );
Window.Graphics.DeleteTexture( sideTexId );
Window.Graphics.DeleteTexture( ref sideTexId );
sideTexId = Window.TerrainAtlas.LoadTextureElement( texLoc );
}

View File

@ -79,7 +79,7 @@ namespace ClassicalSharp.Renderers {
base.Dispose();
Graphics.DeleteVb( skyVbo );
Graphics.DeleteVb( cloudsVbo );
Graphics.DeleteTexture( cloudTexture );
Graphics.DeleteTexture( ref cloudTexture );
}
void RenderClouds( double delta ) {

View File

@ -105,8 +105,8 @@ namespace ClassicalSharp {
public override void Dispose() {
base.Dispose();
index = 0;
Graphics.DeleteTexture( edgeTexId );
Graphics.DeleteTexture( sideTexId );
Graphics.DeleteTexture( ref edgeTexId );
Graphics.DeleteTexture( ref sideTexId );
Graphics.DeleteVb( sidesVboId );
Graphics.DeleteVb( edgesVboId );
sidesVboId = edgesVboId = -1;
@ -127,13 +127,13 @@ namespace ClassicalSharp {
void MakeEdgeTexture() {
int texLoc = Window.BlockInfo.GetOptimTextureLoc( (byte)Map.EdgeBlock, TileSide.Top );
Window.Graphics.DeleteTexture( edgeTexId );
Window.Graphics.DeleteTexture( ref edgeTexId );
edgeTexId = Window.TerrainAtlas.LoadTextureElement( texLoc );
}
void MakeSideTexture() {
int texLoc = Window.BlockInfo.GetOptimTextureLoc( (byte)Map.SidesBlock, TileSide.Top );
Window.Graphics.DeleteTexture( sideTexId );
Window.Graphics.DeleteTexture( ref sideTexId );
sideTexId = Window.TerrainAtlas.LoadTextureElement( texLoc );
}

View File

@ -33,8 +33,8 @@ namespace ClassicalSharp.Renderers {
}
public void Dispose() {
Graphics.DeleteTexture( TextureId );
Graphics.DeleteTexture( nameTextureId );
Graphics.DeleteTexture( ref TextureId );
Graphics.DeleteTexture( ref nameTextureId );
}
public void Render( double deltaTime ) {