OSDN Git Service

#38036 どこでCTextureの解放漏れが発生しているかを容易に識別できるようにするために、CTextureの生成時にラベルを付与できるようにした。(引数最後にラベ...
authoryyagi <yyagi.dtxmania@gmail.com>
Tue, 7 Jan 2020 17:28:42 +0000 (02:28 +0900)
committeryyagi <yyagi.dtxmania@gmail.com>
Tue, 7 Jan 2020 17:28:42 +0000 (02:28 +0900)
DTXMania/コード/全体/TextureFactory.cs
FDK/コード/04.グラフィック/CTexture.cs
FDK/コード/04.グラフィック/CTextureAutofold.cs

index 98575fe..6fe5c68 100644 (file)
@@ -12,12 +12,12 @@ namespace DTXMania
                #region [ 汎用ヘルパー ]
                //-----------------
                #region [ tテクスチャの生成 ]
-               public static CTexture tテクスチャの生成(string fileName)
+               public static CTexture tテクスチャの生成(string fileName, string _label = "" )
                {
-                       return tテクスチャの生成(fileName, false);
+                       return tテクスチャの生成(fileName, false, _label);
                }
 
-               public static CTexture tテクスチャの生成(string fileName, bool b黒を透過する)
+               public static CTexture tテクスチャの生成(string fileName, bool b黒を透過する, string _label = "")
                {
                        if (CDTXMania.Instance == null)
                        {
@@ -25,7 +25,7 @@ namespace DTXMania
                        }
                        try
                        {
-                               return new CTexture(CDTXMania.Instance.Device, fileName, CDTXMania.Instance.TextureFormat, b黒を透過する);
+                               return new CTexture(CDTXMania.Instance.Device, fileName, CDTXMania.Instance.TextureFormat, b黒を透過する, _label);
                        }
                        catch (CTextureCreateFailedException)
                        {
@@ -39,12 +39,12 @@ namespace DTXMania
                        }
                }
 
-               public static CTextureAf tテクスチャの生成Af(string fileName)
+               public static CTextureAf tテクスチャの生成Af(string fileName, string _label = "")
                {
-                       return tテクスチャの生成Af(fileName, false);
+                       return tテクスチャの生成Af(fileName, false, _label);
                }
 
-               public static CTextureAf tテクスチャの生成Af(string fileName, bool b黒を透過する)
+               public static CTextureAf tテクスチャの生成Af(string fileName, bool b黒を透過する, string _label = "")
                {
                        if (CDTXMania.Instance == null)
                        {
@@ -52,7 +52,7 @@ namespace DTXMania
                        }
                        try
                        {
-                               return new CTextureAf(CDTXMania.Instance.Device, fileName, CDTXMania.Instance.TextureFormat, b黒を透過する);
+                               return new CTextureAf(CDTXMania.Instance.Device, fileName, CDTXMania.Instance.TextureFormat, b黒を透過する, _label);
                        }
                        catch (CTextureCreateFailedException)
                        {
@@ -76,12 +76,12 @@ namespace DTXMania
                        t安全にDisposeする(ref tx);
                }
 
-               public static CTexture tテクスチャの生成(byte[] txData)
+               public static CTexture tテクスチャの生成(byte[] txData, string _label = "")
                {
-                       return tテクスチャの生成(txData, false);
+                       return tテクスチャの生成(txData, false, _label);
                }
 
-               public static CTexture tテクスチャの生成(byte[] txData, bool b黒を透過する)
+               public static CTexture tテクスチャの生成(byte[] txData, bool b黒を透過する, string _label = "")
                {
                        if (CDTXMania.Instance == null)
                        {
@@ -94,7 +94,7 @@ namespace DTXMania
                        }
                        try
                        {
-                               return new CTexture(CDTXMania.Instance.Device, txData, CDTXMania.Instance.TextureFormat, b黒を透過する);
+                               return new CTexture(CDTXMania.Instance.Device, txData, CDTXMania.Instance.TextureFormat, b黒を透過する, _label);
                        }
                        catch (CTextureCreateFailedException)
                        {
@@ -103,12 +103,12 @@ namespace DTXMania
                        }
                }
 
-               public static CTexture tテクスチャの生成(Bitmap bitmap)
+               public static CTexture tテクスチャの生成(Bitmap bitmap, string _label = "")
                {
-                       return tテクスチャの生成(bitmap, false);
+                       return tテクスチャの生成(bitmap, false, _label);
                }
 
-               public static CTexture tテクスチャの生成(Bitmap bitmap, bool b黒を透過する)
+               public static CTexture tテクスチャの生成(Bitmap bitmap, bool b黒を透過する, string _label = "")
                {
                        if (CDTXMania.Instance == null)
                        {
@@ -121,7 +121,7 @@ namespace DTXMania
                        }
                        try
                        {
-                               return new CTexture(CDTXMania.Instance.Device, bitmap, CDTXMania.Instance.TextureFormat, b黒を透過する);
+                               return new CTexture(CDTXMania.Instance.Device, bitmap, CDTXMania.Instance.TextureFormat, b黒を透過する, _label);
                        }
                        catch (CTextureCreateFailedException)
                        {
index 0610a35..3a8f8ce 100644 (file)
@@ -85,6 +85,7 @@ namespace FDK
                }
                public Vector3 vc拡大縮小倍率;
                public string filename;
+               public string label;
                #endregion
 
                // コンストラクタ
@@ -103,6 +104,7 @@ namespace FDK
                        this.bFlipY = false;
 //                     this._txData = null;
                        this.filename = "";
+                       this.label = "";
                }
 
                /// <summary>
@@ -116,12 +118,13 @@ namespace FDK
                /// <param name="bitmap">作成元のビットマップ。</param>
                /// <param name="format">テクスチャのフォーマット。</param>
                /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>
-               public CTexture( Device device, Bitmap bitmap, Format format )
+               public CTexture( Device device, Bitmap bitmap, Format format, string _label="" )
                        : this()
                {
                        try
                        {
                                this.Format = format;
+                               this.label = _label;
                                this.sz画像サイズ = new Size( bitmap.Width, bitmap.Height );
                                this.szテクスチャサイズ = this.t指定されたサイズを超えない最適なテクスチャサイズを返す( device, this.sz画像サイズ );
                                this.rc全画像 = new Rectangle( 0, 0, this.sz画像サイズ.Width, this.sz画像サイズ.Height );
@@ -155,8 +158,8 @@ namespace FDK
                /// <param name="n高さ">テクスチャの高さ(希望値)。</param>
                /// <param name="format">テクスチャのフォーマット。</param>
                /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>
-               public CTexture( Device device, int n幅, int n高さ, Format format )
-                       : this( device, n幅, n高さ, format, Pool.Managed )
+               public CTexture( Device device, int n幅, int n高さ, Format format, string _label = "")
+                       : this( device, n幅, n高さ, format, Pool.Managed, _label)
                {
                }
                
@@ -169,16 +172,16 @@ namespace FDK
                /// <param name="format">テクスチャのフォーマット。</param>
                /// <param name="b黒を透過する">画像の黒(0xFFFFFFFF)を透過させるなら true。</param>
                /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>
-               public CTexture( Device device, string strファイル名, Format format, bool b黒を透過する )
-                       : this( device, strファイル名, format, b黒を透過する, Pool.Managed )
+               public CTexture( Device device, string strファイル名, Format format, bool b黒を透過する, string _label = "")
+                       : this( device, strファイル名, format, b黒を透過する, Pool.Managed, _label)
                {
                }
-               public CTexture( Device device, byte[] txData, Format format, bool b黒を透過する )
-                       : this( device, txData, format, b黒を透過する, Pool.Managed )
+               public CTexture( Device device, byte[] txData, Format format, bool b黒を透過する, string _label = "")
+                       : this( device, txData, format, b黒を透過する, Pool.Managed, _label)
                {
                }
-               public CTexture( Device device, Bitmap bitmap, Format format, bool b黒を透過する )
-                       : this( device, bitmap, format, b黒を透過する, Pool.Managed )
+               public CTexture( Device device, Bitmap bitmap, Format format, bool b黒を透過する, string _label = "")
+                       : this( device, bitmap, format, b黒を透過する, Pool.Managed, _label)
                {
                }
                
@@ -196,17 +199,18 @@ namespace FDK
                /// <param name="format">テクスチャのフォーマット。</param>
                /// <param name="pool">テクスチャの管理方法。</param>
                /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>
-               public CTexture( Device device, int n幅, int n高さ, Format format, Pool pool )
-                       : this( device, n幅, n高さ, format, pool, Usage.None, false )
+               public CTexture( Device device, int n幅, int n高さ, Format format, Pool pool, string _label = "")
+                       : this( device, n幅, n高さ, format, pool, Usage.None, false, _label)
                {
                }
                
-               public CTexture( Device device, int n幅, int n高さ, Format format, Pool pool, Usage usage, bool b黒を透過する )
+               public CTexture( Device device, int n幅, int n高さ, Format format, Pool pool, Usage usage, bool b黒を透過する, string _label = "")
                        : this()
                {
                        try
                        {
                                this.Format = format;
+                               this.label = _label;
                                this.sz画像サイズ = new Size( n幅, n高さ );
                                this.szテクスチャサイズ = this.t指定されたサイズを超えない最適なテクスチャサイズを返す( device, this.sz画像サイズ );
                                this.rc全画像 = new Rectangle( 0, 0, this.sz画像サイズ.Width, this.sz画像サイズ.Height );
@@ -251,32 +255,33 @@ namespace FDK
                /// <param name="b黒を透過する">画像の黒(0xFFFFFFFF)を透過させるなら true。</param>
                /// <param name="pool">テクスチャの管理方法。</param>
                /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>
-               public CTexture( Device device, string strファイル名, Format format, bool b黒を透過する, Pool pool )
+               public CTexture( Device device, string strファイル名, Format format, bool b黒を透過する, Pool pool, string _label = "")
                        : this()
                {
-                       MakeTexture( device, strファイル名, format, b黒を透過する, pool );
+                       MakeTexture( device, strファイル名, format, b黒を透過する, pool, _label );
                }
-               public void MakeTexture( Device device, string strファイル名, Format format, bool b黒を透過する, Pool pool )
+               public void MakeTexture( Device device, string strファイル名, Format format, bool b黒を透過する, Pool pool, string _label = "")
                {
                        if ( !File.Exists( strファイル名 ) )               // #27122 2012.1.13 from: ImageInformation では FileNotFound 例外は返ってこないので、ここで自分でチェックする。わかりやすいログのために。
                                throw new FileNotFoundException( string.Format( "ファイルが存在しません。\n[{0}]", strファイル名 ) );
 
                        Byte[] _txData = File.ReadAllBytes( strファイル名 );
                        this.filename = Path.GetFileName( strファイル名 );
-                       MakeTexture( device, _txData, format, b黒を透過する, pool );
+                       MakeTexture( device, _txData, format, b黒を透過する, pool, _label );
                }
 
-               public CTexture( Device device, byte[] txData, Format format, bool b黒を透過する, Pool pool )
+               public CTexture( Device device, byte[] txData, Format format, bool b黒を透過する, Pool pool, string _label = "")
                        : this()
                {
-                       MakeTexture( device, txData, format, b黒を透過する, pool );
+                       MakeTexture( device, txData, format, b黒を透過する, pool, _label );
                }
-               public void MakeTexture( Device device, byte[] txData, Format format, bool b黒を透過する, Pool pool )
+               public void MakeTexture( Device device, byte[] txData, Format format, bool b黒を透過する, Pool pool, string _label = "")
                {
                        try
                        {
                                var information = ImageInformation.FromMemory( txData );
                                this.Format = format;
+                               this.label = _label;
                                this.sz画像サイズ = new Size( information.Width, information.Height );
                                this.rc全画像 = new Rectangle( 0, 0, this.sz画像サイズ.Width, this.sz画像サイズ.Height );
                                int colorKey = ( b黒を透過する ) ? unchecked( (int) 0xFF000000 ) : 0;
@@ -304,16 +309,17 @@ namespace FDK
                        }
                }
 
-               public CTexture( Device device, Bitmap bitmap, Format format, bool b黒を透過する, Pool pool )
+               public CTexture( Device device, Bitmap bitmap, Format format, bool b黒を透過する, Pool pool, string _label = "")
                        : this()
                {
-                       MakeTexture( device, bitmap, format, b黒を透過する, pool );
+                       MakeTexture( device, bitmap, format, b黒を透過する, pool, _label );
                }
-               public void MakeTexture( Device device, Bitmap bitmap, Format format, bool b黒を透過する, Pool pool )
+               public void MakeTexture( Device device, Bitmap bitmap, Format format, bool b黒を透過する, Pool pool, string _label = "")
                {
                        try
                        {
                                this.Format = format;
+                               this.label = _label;
                                this.sz画像サイズ = new Size( bitmap.Width, bitmap.Height );
                                this.rc全画像 = new Rectangle( 0, 0, this.sz画像サイズ.Width, this.sz画像サイズ.Height );
                                int colorKey = ( b黒を透過する ) ? unchecked( (int) 0xFF000000 ) : 0;
@@ -641,7 +647,7 @@ namespace FDK
                        // CTextureのDispose漏れと見做して警告をログ出力する
                        if (!this.bSharpDXTextureDispose完了済み)
                        {
-                               Trace.TraceWarning("CTexture: Dispose漏れを検出しました。(Size=({0}, {1}), filename={2})", sz画像サイズ.Width, sz画像サイズ.Height, filename );
+                               Trace.TraceWarning("CTexture: Dispose漏れを検出しました。(Size=({0}, {1}), filename={2}, label={3})", sz画像サイズ.Width, sz画像サイズ.Height, filename, label );
                        }
                        this.Dispose(false);
                }
index 488f823..2fe4433 100644 (file)
@@ -31,8 +31,8 @@ namespace FDK
                /// <param name="format">テクスチャのフォーマット。</param>
                /// <param name="b黒を透過する">画像の黒(0xFFFFFFFF)を透過させるなら true。</param>
                /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>
-               public CTextureAf( Device device, string strファイル名, Format format, bool b黒を透過する )
-                       : this( device, strファイル名, format, b黒を透過する, Pool.Managed )
+               public CTextureAf( Device device, string strファイル名, Format format, bool b黒を透過する, string _label = "")
+                       : this( device, strファイル名, format, b黒を透過する, Pool.Managed, _label )
                {
                }
 
@@ -49,15 +49,15 @@ namespace FDK
                /// <param name="b黒を透過する">画像の黒(0xFFFFFFFF)を透過させるなら true。</param>
                /// <param name="pool">テクスチャの管理方法。</param>
                /// <exception cref="CTextureCreateFailedException">テクスチャの作成に失敗しました。</exception>
-               public CTextureAf( Device device, string strファイル名, Format format, bool b黒を透過する, Pool pool )
+               public CTextureAf( Device device, string strファイル名, Format format, bool b黒を透過する, Pool pool, string _label = "")
                {
-                       MakeTexture( device, strファイル名, format, b黒を透過する, pool );
+                       MakeTexture( device, strファイル名, format, b黒を透過する, pool, _label );
                }
 
 
 
 
-               public new void MakeTexture( Device device, string strファイル名, Format format, bool b黒を透過する, Pool pool )
+               public new void MakeTexture( Device device, string strファイル名, Format format, bool b黒を透過する, Pool pool, string _label = "")
                {
                        if ( !File.Exists( strファイル名 ) )               // #27122 2012.1.13 from: ImageInformation では FileNotFound 例外は返ってこないので、ここで自分でチェックする。わかりやすいログのために。
                                throw new FileNotFoundException( string.Format( "ファイルが存在しません。\n[{0}]", strファイル名 ) );
@@ -71,7 +71,7 @@ namespace FDK
                        if ( !bサイズは2の累乗でなければならない && b条件付きでサイズは2の累乗でなくてもOK )
                        {
                                //Debug.WriteLine( Path.GetFileName( strファイル名 )  + ": 最適化は不要です。" );
-                               base.MakeTexture( device, strファイル名, format, b黒を透過する, pool );
+                               base.MakeTexture( device, strファイル名, format, b黒を透過する, pool, _label);
                                return;
                        }
 
@@ -154,7 +154,7 @@ namespace FDK
                        g = null;
                        bmpOrg.Dispose();
                        bmpOrg = null;
-                       base.MakeTexture( device, bmpNew, format, b黒を透過する, pool );
+                       base.MakeTexture( device, bmpNew, format, b黒を透過する, pool, _label );
                        bmpNew.Dispose();
                        bmpNew = null;
                        #endregion