Tue, 12/23/2025 - 14:37
Forums:
Hello everyone. I am new to this repo. I am trying to create temporary shape visual while drawing line for my mini CAD program. This is my code snippet that updates and redisplays line while mouse moving. But if i move mouse fastly, it crashes. How to solve this problem properly? Thanks.
bool showTempPreview(const gp_Pnt &startPnt, const gp_Pnt &endPnt)
{
// Early null checks
if (context_.IsNull() || view_.IsNull())
{
return false;
}
// Check if points are too close (would create invalid edge)
double dist = startPnt.Distance(endPnt);
if (dist < 0.001)
{
return false;
}
// Create the temporary edge
BRepBuilderAPI_MakeEdge edgeBuilder(startPnt, endPnt);
if (!edgeBuilder.IsDone())
{
return false;
}
TopoDS_Edge tempEdge = edgeBuilder.Edge();
if (tempEdge.IsNull())
{
return false;
}
if (!tempPreviewActive_)
{
// First time: create new line object
tempLine_ = new AIS_Shape(tempEdge);
// Set dashed line style
Handle(Prs3d_LineAspect) lineAspect = new Prs3d_LineAspect(
Quantity_NOC_CYAN, Aspect_TOL_DASH, 2.0);
tempLine_->Attributes()->SetLineAspect(lineAspect);
tempLine_->SetDisplayMode(AIS_WireFrame);
context_->Display(tempLine_, AIS_WireFrame, -1, false);
tempPreviewActive_ = true;
}
else if (!tempLine_.IsNull())
{
// Update existing line
tempLine_->SetShape(tempEdge);
context_->Redisplay(tempLine_, true);
}
return true;
}