@@ -72,6 +72,9 @@ public void InvalidatePixels()
7272
7373 public override void Dispose ( )
7474 {
75+ if ( IsDisposed )
76+ return ;
77+
7578 this . canvas . Dispose ( ) ;
7679 this . surface . Dispose ( ) ;
7780 this . image . Dispose ( ) ;
@@ -106,6 +109,9 @@ private unsafe void UpdateLocalPixels()
106109
107110 public unsafe void Update ( ReadOnlySpan < Color > pixels )
108111 {
112+ if ( IsDisposed )
113+ throw new InvalidOperationException ( "Cannot use disposed texture!" ) ;
114+
109115 Color * buffer = null ;
110116 try
111117 {
@@ -144,6 +150,9 @@ private void TextureFlip(ReadOnlySpan<Color> src, Span<Color> dest)
144150
145151 public ICanvas GetCanvas ( )
146152 {
153+ if ( IsDisposed )
154+ throw new InvalidOperationException ( "Cannot use disposed texture!" ) ;
155+
147156 if ( Options . HasFlag ( TextureOptions . NonRenderTarget ) )
148157 {
149158 throw new InvalidOperationException ( "Cannot render to a texture with the TextureOptions.NonRenderTarget flag." ) ;
@@ -164,21 +173,36 @@ public void ApplyChanges()
164173
165174 public SKSurface GetSurface ( )
166175 {
176+ if ( IsDisposed )
177+ throw new InvalidOperationException ( "Cannot use disposed texture!" ) ;
178+
167179 return surface ;
168180 }
169181
170182 public SKImage GetImage ( )
171183 {
184+ if ( IsDisposed )
185+
186+ if ( IsDisposed )
187+ throw new InvalidOperationException ( "Cannot use disposed texture!" ) ;
188+ throw new InvalidOperationException ( "Cannot use disposed texture!" ) ;
189+
172190 return image ;
173191 }
174192
175193 public uint GetGLTexture ( )
176194 {
195+ if ( IsDisposed )
196+ throw new InvalidOperationException ( "Cannot use disposed texture!" ) ;
197+
177198 return glTexture ;
178199 }
179200
180201 public void Encode ( Stream destination , TextureEncoding encoding )
181202 {
203+ if ( IsDisposed )
204+ throw new InvalidOperationException ( "Cannot use disposed texture!" ) ;
205+
182206 var data = image . Encode ( encoding switch
183207 {
184208 TextureEncoding . PNG => SKEncodedImageFormat . Png ,
0 commit comments