Skip to content

Commit

Permalink
grblcore now calls grblcommand dispose before clearing queues
Browse files Browse the repository at this point in the history
opengl thread has lowest priority to free resources for communication threads
  • Loading branch information
GabeMx5 committed Jun 16, 2024
1 parent c81d63e commit cea12ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 13 additions & 4 deletions LaserGRBL/Core/GrblCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ public void AbortProgram()

lock (this)
{
mQueue.Clear(); //flush the queue of item to send
ClearQueue(mQueue); //flush the queue of item to send
mQueue.Enqueue(new GrblCommand("M5")); //shut down laser
}
}
Expand Down Expand Up @@ -2679,10 +2679,19 @@ private void OnProgramEnd()
private bool InPause
{ get { return mMachineStatus != MacStatus.Run && mMachineStatus != MacStatus.Idle; } }

private void ClearQueue(bool sent)
private void ClearQueue(Queue<GrblCommand> queue)
{
foreach (GrblCommand command in queue)
{
command.Dispose();
}
queue.Clear();
}

private void ClearQueue(bool sent)
{
mQueue.Clear();
mPending.Clear();
ClearQueue(mQueue);
ClearQueue(mPending);
if (sent) mSent.Clear();
mRetryQueue = null;
}
Expand Down
4 changes: 1 addition & 3 deletions LaserGRBL/UserControls/GrblPanel3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Net.Mail;
using System.Runtime.Remoting.Messaging;
using System.Threading;
using System.Windows.Forms;
using static LaserGRBL.ProgramRange;
Expand Down Expand Up @@ -138,7 +136,7 @@ public GrblPanel3D()
mGrid = new Grid3D();

OnColorChange();
TH = new Tools.ThreadObject(DrawScene, 10, true, "OpenGL", InitializeOpenGL, ThreadPriority.Normal, ApartmentState.STA);
TH = new Tools.ThreadObject(DrawScene, 10, true, "OpenGL", InitializeOpenGL, ThreadPriority.Lowest, ApartmentState.STA);
TH.Start();
}

Expand Down

0 comments on commit cea12ff

Please sign in to comment.