Skip to content

Commit

Permalink
SceneViewport - Add proper class disposal
Browse files Browse the repository at this point in the history
  • Loading branch information
NessieHax committed Mar 13, 2024
1 parent 29a9e4e commit 0a01a4c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions PCK-Studio/Forms/Editor/CustomSkinEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ private void deleteToolStripMenuItem_Click(object sender, EventArgs e)

private void CustomSkinEditor_FormClosing(object sender, FormClosingEventArgs e)
{
renderer3D1.Dispose();
}

private void outlineColorButton_Click(object sender, EventArgs e)
Expand Down
23 changes: 18 additions & 5 deletions PCK-Studio/Rendering/SceneViewport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ public int RefreshRate
private int refreshRate = 60;
private Timer timer;

private ShaderProgram colorShader;
private VertexArray VAO;
private VertexBuffer VBO;
private IndexBuffer IBO;
private ShaderProgram colorShader;
private bool isInitialized;

protected void Init()
Expand All @@ -71,9 +70,9 @@ protected void Init()
Debug.Fail("Already Initializted.");
return;
}
MakeCurrent();
colorShader = ShaderProgram.Create(Resources.plainColorVertexShader, Resources.plainColorFragmentShader);
VAO = new VertexArray();
VBO = new VertexBuffer();
IBO = IndexBuffer.Create(
0, 1,
1, 2,
Expand All @@ -92,7 +91,7 @@ protected void Init()
VertexBufferLayout layout = new VertexBufferLayout();
layout.Add(ShaderDataType.Float3);
layout.Add(ShaderDataType.Float4);
VAO.AddBuffer(VBO, layout);
VAO.AddNewBuffer(layout);
isInitialized = true;
}

Expand All @@ -108,6 +107,20 @@ public SceneViewport() : base()
isInitialized = false;
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
timer.Stop();
timer.Dispose();
}
MakeCurrent();
VAO.Dispose();
IBO.Dispose();
colorShader.Dispose();
base.Dispose(disposing);
}


protected void DrawBoundingBox(Matrix4 transform, BoundingBox boundingBox, Color color)
{
Expand Down Expand Up @@ -139,7 +152,7 @@ protected void DrawBoundingBox(Matrix4 transform, BoundingBox boundingBox, Color
];

VAO.Bind();
VBO.SetData(vertices);
VAO.GetBuffer(0).SetData(vertices);
IBO.Bind();
GL.DrawElements(PrimitiveType.Lines, IBO.GetCount(), DrawElementsType.UnsignedInt, 0);
GL.DepthFunc(DepthFunction.Less);
Expand Down

0 comments on commit 0a01a4c

Please sign in to comment.