Skip to content

Commit 1cbe348

Browse files
committed
RenderTarget: Throw an error when disposing a bound target
1 parent 4a468ff commit 1cbe348

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Graphics/RenderTarget2D.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ protected override void Dispose(bool disposing)
180180
{
181181
if (!IsDisposed)
182182
{
183+
for (int i = 0; i < GraphicsDevice.renderTargetCount; i += 1)
184+
{
185+
if (GraphicsDevice.renderTargetBindings[i].RenderTarget == this)
186+
{
187+
throw new InvalidOperationException("Disposing target that is still bound");
188+
}
189+
}
190+
183191
IntPtr toDispose = Interlocked.Exchange(ref glColorBuffer, IntPtr.Zero);
184192
if (toDispose != IntPtr.Zero)
185193
{

src/Graphics/RenderTargetCube.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ protected override void Dispose(bool disposing)
224224
{
225225
if (!IsDisposed)
226226
{
227+
for (int i = 0; i < GraphicsDevice.renderTargetCount; i += 1)
228+
{
229+
if (GraphicsDevice.renderTargetBindings[i].RenderTarget == this)
230+
{
231+
throw new InvalidOperationException("Disposing target that is still bound");
232+
}
233+
}
234+
227235
IntPtr toDispose = Interlocked.Exchange(ref glColorBuffer, IntPtr.Zero);
228236
if (toDispose != IntPtr.Zero)
229237
{

0 commit comments

Comments
 (0)