Skip to content

Commit 0b19f8c

Browse files
MarioalexsaneXpl0it3r
authored andcommitted
Implement checks for disposed objects
1 parent 9ceb6f7 commit 0b19f8c

File tree

20 files changed

+65
-45
lines changed

20 files changed

+65
-45
lines changed

src/SFML.Audio/Music.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class Music : ObjectBase
2828
public Music(string filename) :
2929
base(sfMusic_createFromFile(filename))
3030
{
31-
if (CPointer == IntPtr.Zero)
31+
if (IsInvalid)
3232
{
3333
throw new LoadingFailedException("music", filename);
3434
}
@@ -52,7 +52,7 @@ public Music(Stream stream) :
5252
myStream = new StreamAdaptor(stream);
5353
CPointer = sfMusic_createFromStream(myStream.InputStreamPtr);
5454

55-
if (CPointer == IntPtr.Zero)
55+
if (IsInvalid)
5656
{
5757
throw new LoadingFailedException("music");
5858
}
@@ -83,7 +83,7 @@ public Music(byte[] bytes) :
8383
{
8484
pin.Free();
8585
}
86-
if (CPointer == IntPtr.Zero)
86+
if (IsInvalid)
8787
{
8888
throw new LoadingFailedException("music");
8989
}
@@ -335,7 +335,7 @@ public TimeSpan LoopPoints
335335
////////////////////////////////////////////////////////////
336336
public override string ToString()
337337
{
338-
if (CPointer == IntPtr.Zero)
338+
if (IsInvalid)
339339
return MakeDisposedObjectString();
340340

341341
return "[Music]" +

src/SFML.Audio/Sound.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public float Attenuation
270270
////////////////////////////////////////////////////////////
271271
public override string ToString()
272272
{
273-
if (CPointer == IntPtr.Zero)
273+
if (IsInvalid)
274274
return MakeDisposedObjectString();
275275

276276
return "[Sound]" +

src/SFML.Audio/SoundBuffer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class SoundBuffer : ObjectBase
2727
public SoundBuffer(string filename) :
2828
base(sfSoundBuffer_createFromFile(filename))
2929
{
30-
if (CPointer == IntPtr.Zero)
30+
if (IsInvalid)
3131
{
3232
throw new LoadingFailedException("sound buffer", filename);
3333
}
@@ -52,7 +52,7 @@ public SoundBuffer(Stream stream) :
5252
CPointer = sfSoundBuffer_createFromStream(adaptor.InputStreamPtr);
5353
}
5454

55-
if (CPointer == IntPtr.Zero)
55+
if (IsInvalid)
5656
{
5757
throw new LoadingFailedException("sound buffer");
5858
}
@@ -81,7 +81,7 @@ public SoundBuffer(byte[] bytes) :
8181
{
8282
pin.Free();
8383
}
84-
if (CPointer == IntPtr.Zero)
84+
if (IsInvalid)
8585
{
8686
throw new LoadingFailedException("sound buffer");
8787
}
@@ -107,7 +107,7 @@ public SoundBuffer(short[] samples, uint channelCount, uint sampleRate) :
107107
}
108108
}
109109

110-
if (CPointer == IntPtr.Zero)
110+
if (IsInvalid)
111111
{
112112
throw new LoadingFailedException("sound buffer");
113113
}
@@ -199,7 +199,7 @@ public short[] Samples
199199
////////////////////////////////////////////////////////////
200200
public override string ToString()
201201
{
202-
if (CPointer == IntPtr.Zero)
202+
if (IsInvalid)
203203
return MakeDisposedObjectString();
204204

205205
return "[SoundBuffer]" +

src/SFML.Audio/SoundBufferRecorder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public SoundBuffer SoundBuffer
3434
////////////////////////////////////////////////////////////
3535
public override string ToString()
3636
{
37-
if (CPointer == IntPtr.Zero)
37+
if (IsInvalid)
3838
return MakeDisposedObjectString();
3939

4040
return "[SoundBufferRecorder]" +

src/SFML.Audio/SoundRecorder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static bool IsAvailable
126126
////////////////////////////////////////////////////////////
127127
public override string ToString()
128128
{
129-
if (CPointer == IntPtr.Zero)
129+
if (IsInvalid)
130130
return MakeDisposedObjectString();
131131

132132
return "[SoundRecorder]" + " SampleRate(" + SampleRate + ")";

src/SFML.Audio/SoundStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public Time PlayingOffset
237237
////////////////////////////////////////////////////////////
238238
public override string ToString()
239239
{
240-
if (CPointer == IntPtr.Zero)
240+
if (IsInvalid)
241241
return MakeDisposedObjectString();
242242

243243
return "[SoundStream]" +

src/SFML.Graphics/Font.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class Font : ObjectBase
2626
////////////////////////////////////////////////////////////
2727
public Font(string filename) : base(sfFont_createFromFile(filename))
2828
{
29-
if (CPointer == IntPtr.Zero)
29+
if (IsInvalid)
3030
{
3131
throw new LoadingFailedException("font", filename);
3232
}
@@ -46,7 +46,7 @@ public Font(Stream stream) : base(IntPtr.Zero)
4646
CPointer = sfFont_createFromStream(adaptor.InputStreamPtr);
4747
}
4848

49-
if (CPointer == IntPtr.Zero)
49+
if (IsInvalid)
5050
{
5151
throw new LoadingFailedException("font");
5252
}
@@ -71,7 +71,7 @@ public Font(byte[] bytes) :
7171
{
7272
pin.Free();
7373
}
74-
if (CPointer == IntPtr.Zero)
74+
if (IsInvalid)
7575
{
7676
throw new LoadingFailedException("font");
7777
}

src/SFML.Graphics/Image.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public Image(uint width, uint height) : this(width, height, Color.Black) { }
3535
////////////////////////////////////////////////////////////
3636
public Image(uint width, uint height, Color color) : base(sfImage_createFromColor(width, height, color))
3737
{
38-
if (CPointer == IntPtr.Zero)
38+
if (IsInvalid)
3939
{
4040
throw new LoadingFailedException("image");
4141
}
@@ -50,7 +50,7 @@ public Image(uint width, uint height, Color color) : base(sfImage_createFromColo
5050
////////////////////////////////////////////////////////////
5151
public Image(string filename) : base(sfImage_createFromFile(filename))
5252
{
53-
if (CPointer == IntPtr.Zero)
53+
if (IsInvalid)
5454
{
5555
throw new LoadingFailedException("image", filename);
5656
}
@@ -71,7 +71,7 @@ public Image(Stream stream) :
7171
CPointer = sfImage_createFromStream(adaptor.InputStreamPtr);
7272
}
7373

74-
if (CPointer == IntPtr.Zero)
74+
if (IsInvalid)
7575
{
7676
throw new LoadingFailedException("image");
7777
}
@@ -96,7 +96,7 @@ public Image(byte[] bytes) :
9696
{
9797
pin.Free();
9898
}
99-
if (CPointer == IntPtr.Zero)
99+
if (IsInvalid)
100100
{
101101
throw new LoadingFailedException("image");
102102
}
@@ -133,7 +133,7 @@ public Image(Color[,] pixels) :
133133
}
134134
}
135135

136-
if (CPointer == IntPtr.Zero)
136+
if (IsInvalid)
137137
{
138138
throw new LoadingFailedException("image");
139139
}
@@ -159,7 +159,7 @@ public Image(uint width, uint height, byte[] pixels) :
159159
}
160160
}
161161

162-
if (CPointer == IntPtr.Zero)
162+
if (IsInvalid)
163163
{
164164
throw new LoadingFailedException("image");
165165
}
@@ -356,7 +356,7 @@ public void FlipVertically()
356356
////////////////////////////////////////////////////////////
357357
public override string ToString()
358358
{
359-
if (CPointer == IntPtr.Zero)
359+
if (IsInvalid)
360360
return MakeDisposedObjectString();
361361

362362
return $"[Image] Size({Size})";

src/SFML.Graphics/RenderTexture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ public void ResetGLStates()
497497
////////////////////////////////////////////////////////////
498498
public override string ToString()
499499
{
500-
if (CPointer == IntPtr.Zero)
500+
if (IsInvalid)
501501
return MakeDisposedObjectString();
502502

503503
return "[RenderTexture]" +

src/SFML.Graphics/RenderWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ public Image Capture()
716716
////////////////////////////////////////////////////////////
717717
public override string ToString()
718718
{
719-
if (CPointer == IntPtr.Zero)
719+
if (IsInvalid)
720720
return MakeDisposedObjectString();
721721

722722
return "[RenderWindow]" +

0 commit comments

Comments
 (0)