minor change for the dispose exception for disposables.

This commit is contained in:
Harrison Deng 2019-01-12 23:40:52 -06:00
parent bfdc36a3e2
commit edd2e94a6a
2 changed files with 8 additions and 8 deletions

View File

@ -44,7 +44,7 @@ namespace RecrownedAthenaeum.Render
public void Begin(PrimitiveType primitiveType) public void Begin(PrimitiveType primitiveType)
{ {
if (began) throw new InvalidOperationException("Begin is being called twice before being ended."); if (began) throw new InvalidOperationException("Begin is being called twice before being ended.");
if (disposed) throw new ObjectDisposedException(typeof(PrimitiveBatch).Name); if (disposed) throw new ObjectDisposedException(this.GetType().Name);
this.primitiveType = primitiveType; this.primitiveType = primitiveType;
verticesPerPrimitive = 0; verticesPerPrimitive = 0;
switch (primitiveType) switch (primitiveType)
@ -63,7 +63,7 @@ namespace RecrownedAthenaeum.Render
/// </summary> /// </summary>
public void End() public void End()
{ {
if (disposed) throw new ObjectDisposedException(typeof(PrimitiveBatch).Name); if (disposed) throw new ObjectDisposedException(this.GetType().Name);
if (!began) throw new InvalidOperationException("Begin must be called before ending."); if (!began) throw new InvalidOperationException("Begin must be called before ending.");
Flush(); Flush();
@ -77,7 +77,7 @@ namespace RecrownedAthenaeum.Render
public void AddVertex(Vector2 vertex, Color color) public void AddVertex(Vector2 vertex, Color color)
{ {
if (!began) throw new InvalidOperationException("Begin needs to be called before adding vertex."); if (!began) throw new InvalidOperationException("Begin needs to be called before adding vertex.");
if (disposed) throw new ObjectDisposedException(typeof(PrimitiveBatch).Name); if (disposed) throw new ObjectDisposedException(this.GetType().Name);
if (bufferPosition + verticesPerPrimitive >= MaxVertices && (bufferPosition % MaxVertices == 0)) if (bufferPosition + verticesPerPrimitive >= MaxVertices && (bufferPosition % MaxVertices == 0))
{ {
if (primitiveType != PrimitiveType.LineStrip && primitiveType != PrimitiveType.TriangleStrip) if (primitiveType != PrimitiveType.LineStrip && primitiveType != PrimitiveType.TriangleStrip)
@ -99,7 +99,7 @@ namespace RecrownedAthenaeum.Render
public void Flush() public void Flush()
{ {
if (!began) throw new InvalidOperationException("Begin needs to be called before flushing."); if (!began) throw new InvalidOperationException("Begin needs to be called before flushing.");
if (disposed) throw new ObjectDisposedException(typeof(PrimitiveBatch).Name); if (disposed) throw new ObjectDisposedException(this.GetType().Name);
if (bufferPosition == 0) return; if (bufferPosition == 0) return;
graphicsDevice.DrawUserPrimitives(primitiveType, vertices.ToArray(), 0, bufferPosition / verticesPerPrimitive); graphicsDevice.DrawUserPrimitives(primitiveType, vertices.ToArray(), 0, bufferPosition / verticesPerPrimitive);
@ -121,7 +121,7 @@ namespace RecrownedAthenaeum.Render
} }
else else
{ {
throw new ObjectDisposedException(typeof(PrimitiveBatch).Name); if (disposed) throw new ObjectDisposedException(this.GetType().Name);
} }
} }
} }

View File

@ -29,7 +29,7 @@ namespace RecrownedAthenaeum.Render
public void Begin(bool filled) public void Begin(bool filled)
{ {
filling = filled; filling = filled;
if (disposed) throw new ObjectDisposedException(typeof(PrimitiveBatch).Name); if (disposed) throw new ObjectDisposedException(GetType().Name);
if (began) throw new InvalidOperationException("Cannot begin twice."); if (began) throw new InvalidOperationException("Cannot begin twice.");
primitiveBatch.Begin(filled ? PrimitiveType.TriangleStrip : PrimitiveType.LineStrip); primitiveBatch.Begin(filled ? PrimitiveType.TriangleStrip : PrimitiveType.LineStrip);
began = true; began = true;
@ -37,7 +37,7 @@ namespace RecrownedAthenaeum.Render
public void End() public void End()
{ {
if (disposed) throw new ObjectDisposedException(typeof(PrimitiveBatch).Name); if (disposed) throw new ObjectDisposedException(GetType().Name);
if (!began) throw new InvalidOperationException("Cannot end before beginning."); if (!began) throw new InvalidOperationException("Cannot end before beginning.");
primitiveBatch.End(); primitiveBatch.End();
began = false; began = false;
@ -55,7 +55,7 @@ namespace RecrownedAthenaeum.Render
/// <param name="rotation">Rotation of rectangle. Default is 0 radians.</param> /// <param name="rotation">Rotation of rectangle. Default is 0 radians.</param>
public void Rectangle(int x, int y, int width, int height, Color color, double rotation = 0) public void Rectangle(int x, int y, int width, int height, Color color, double rotation = 0)
{ {
if (disposed) throw new ObjectDisposedException(typeof(PrimitiveBatch).Name); if (disposed) throw new ObjectDisposedException(GetType().Name);
if (!began) throw new InvalidOperationException("Renderer must be started by calling Begin."); if (!began) throw new InvalidOperationException("Renderer must be started by calling Begin.");
Vector2[] corners = new Vector2[4]; Vector2[] corners = new Vector2[4];