I am trying to create transient graphics like in autocad, but it drops me memory coruption error. I will attach some code that works in autocad but not in GSTARcad. I think that EraseTransients is not working correct.
Does anybody know how to fix it? I know about UpdateTransient function, but it is not what i need for my purposes.
using Gssoft.Gscad.DatabaseServices;
using Gssoft.Gscad.EditorInput;
using Gssoft.Gscad.Geometry;
using Gssoft.Gscad.GraphicsInterface;
using Gssoft.Gscad.Runtime;
using System.Diagnostics;
using acGI = Gssoft.Gscad.GraphicsInterface;
namespace GStarTransient
{
public class Class1
{
Editor ed = Gssoft.Gscad.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
DBObjectCollection markers = null;
TransientManager tm = acGI.TransientManager.CurrentTransientManager;
[CommandMethod("trc")]
public void TransientStart()
{
PointMonitorEventHandler handler = null;
handler = delegate (object sender, PointMonitorEventArgs e)
{
Point3d point = e.Context.RawPoint;
UpdateTransient(point);
};
ed.PointMonitor += handler;
}
private void UpdateTransient(Point3d point)
{
RemoveTransient();
markers = new DBObjectCollection();
Line line1 = new Line(Point3d.Origin, point);
AddTransient(line1);
Line line2 = new Line(Point3d.Origin, new Point3d(point.X - 50, point.Y, point.Z));
AddTransient(line2);
}
private void AddTransient(Entity entity)
{
try
{
entity.LineWeight = LineWeight.LineWeight030;
entity.ColorIndex = 1;
tm.AddTransient(entity, acGI.TransientDrawingMode.DirectShortTerm, 128, new IntegerCollection());
markers.Add(entity);
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
private void RemoveTransient()
{
try
{
if (markers != null)
{
tm.EraseTransients(acGI.TransientDrawingMode.DirectShortTerm, 128, new IntegerCollection());
foreach (DBObject dBObject in markers)
dBObject.Dispose();
markers = null;
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
}
}