Skip to content

Commit 9ceb6f7

Browse files
MarioalexsaneXpl0it3r
authored andcommitted
Do not access properties within ToString methods for disposed objects
1 parent 2eeccf0 commit 9ceb6f7

File tree

17 files changed

+63
-3
lines changed

17 files changed

+63
-3
lines changed

src/SFML.Audio/Music.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ public TimeSpan LoopPoints
335335
////////////////////////////////////////////////////////////
336336
public override string ToString()
337337
{
338+
if (CPointer == IntPtr.Zero)
339+
return MakeDisposedObjectString();
340+
338341
return "[Music]" +
339342
" SampleRate(" + SampleRate + ")" +
340343
" ChannelCount(" + ChannelCount + ")" +

src/SFML.Audio/Sound.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ public float Attenuation
270270
////////////////////////////////////////////////////////////
271271
public override string ToString()
272272
{
273+
if (CPointer == IntPtr.Zero)
274+
return MakeDisposedObjectString();
275+
273276
return "[Sound]" +
274277
" Status(" + Status + ")" +
275278
" Loop(" + Loop + ")" +

src/SFML.Audio/SoundBuffer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ public short[] Samples
199199
////////////////////////////////////////////////////////////
200200
public override string ToString()
201201
{
202+
if (CPointer == IntPtr.Zero)
203+
return MakeDisposedObjectString();
204+
202205
return "[SoundBuffer]" +
203206
" SampleRate(" + SampleRate + ")" +
204207
" ChannelCount(" + ChannelCount + ")" +

src/SFML.Audio/SoundBufferRecorder.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23

34
namespace SFML.Audio
@@ -33,6 +34,9 @@ public SoundBuffer SoundBuffer
3334
////////////////////////////////////////////////////////////
3435
public override string ToString()
3536
{
37+
if (CPointer == IntPtr.Zero)
38+
return MakeDisposedObjectString();
39+
3640
return "[SoundBufferRecorder]" +
3741
" SampleRate(" + SampleRate + ")" +
3842
" SoundBuffer(" + SoundBuffer + ")";

src/SFML.Audio/SoundRecorder.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ public static bool IsAvailable
126126
////////////////////////////////////////////////////////////
127127
public override string ToString()
128128
{
129+
if (CPointer == IntPtr.Zero)
130+
return MakeDisposedObjectString();
131+
129132
return "[SoundRecorder]" + " SampleRate(" + SampleRate + ")";
130133
}
131134

src/SFML.Audio/SoundStream.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ public Time PlayingOffset
237237
////////////////////////////////////////////////////////////
238238
public override string ToString()
239239
{
240+
if (CPointer == IntPtr.Zero)
241+
return MakeDisposedObjectString();
242+
240243
return "[SoundStream]" +
241244
" SampleRate(" + SampleRate + ")" +
242245
" ChannelCount(" + ChannelCount + ")" +

src/SFML.Graphics/Image.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,13 @@ public void FlipVertically()
354354
/// </summary>
355355
/// <returns>String description of the object</returns>
356356
////////////////////////////////////////////////////////////
357-
public override string ToString() => $"[Image] Size({Size})";
357+
public override string ToString()
358+
{
359+
if (CPointer == IntPtr.Zero)
360+
return MakeDisposedObjectString();
361+
362+
return $"[Image] Size({Size})";
363+
}
358364

359365
////////////////////////////////////////////////////////////
360366
/// <summary>

src/SFML.Graphics/RenderTexture.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ public void ResetGLStates()
497497
////////////////////////////////////////////////////////////
498498
public override string ToString()
499499
{
500+
if (CPointer == IntPtr.Zero)
501+
return MakeDisposedObjectString();
502+
500503
return "[RenderTexture]" +
501504
" Size(" + Size + ")" +
502505
" Texture(" + Texture + ")" +

src/SFML.Graphics/RenderWindow.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,9 @@ public Image Capture()
716716
////////////////////////////////////////////////////////////
717717
public override string ToString()
718718
{
719+
if (CPointer == IntPtr.Zero)
720+
return MakeDisposedObjectString();
721+
719722
return "[RenderWindow]" +
720723
" Size(" + Size + ")" +
721724
" Position(" + Position + ")" +
@@ -802,6 +805,8 @@ protected override void Destroy(bool disposing)
802805
{
803806
myDefaultView.Dispose();
804807
}
808+
809+
myDefaultView = null;
805810
}
806811

807812
////////////////////////////////////////////////////////////

src/SFML.Graphics/Shader.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,9 @@ public static bool IsGeometryAvailable
712712
////////////////////////////////////////////////////////////
713713
public override string ToString()
714714
{
715+
if (CPointer == IntPtr.Zero)
716+
return MakeDisposedObjectString();
717+
715718
return "[Shader]";
716719
}
717720

0 commit comments

Comments
 (0)