From b3df595769cd8d2bb22fbd48f56cbbd1edee41ac Mon Sep 17 00:00:00 2001 From: whitequark Date: Sun, 17 Apr 2016 01:16:47 +0000 Subject: [PATCH] Don't crash after right-clicking on derived entities. --- src/mouse.cpp | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/src/mouse.cpp b/src/mouse.cpp index f39654c7..79fc0fde 100644 --- a/src/mouse.cpp +++ b/src/mouse.cpp @@ -573,33 +573,27 @@ void GraphicsWindow::MouseRightUp(double x, double y) { } if(gs.comments > 0 || gs.points > 0) { AddContextMenuItem("Snap to Grid", CMNU_SNAP_TO_GRID); - - if(gs.points == 1) { - hRequest hr = gs.point[0].request(); - if(hr.v != 0) { - Request *r = SK.GetRequest(hr); - int index = r->IndexOfPoint(gs.point[0]); - if((r->type == Request::CUBIC && (index > 1 && index < r->extraPoints + 2)) || - r->type == Request::CUBIC_PERIODIC) { - AddContextMenuItem("Remove Spline Point", CMNU_REMOVE_SPLINE_PT); - } - } - } } - if(gs.entities == 1) { - hRequest hr = gs.entity[0].request(); - if(hr.v != 0) { - Request *r = SK.GetRequest(hr); - if(r->type == Request::CUBIC || r->type == Request::CUBIC_PERIODIC) { - Entity *e = SK.GetEntity(gs.entity[0]); - e->GetDistance(Point2d::From(x, y)); - addAfterPoint = e->dogd.data; - if(addAfterPoint == -1) oops(); - // Skip derivative point. - if(r->type == Request::CUBIC) addAfterPoint++; - AddContextMenuItem("Add Spline Point", CMNU_ADD_SPLINE_PT); - } + + if(gs.points == 1 && gs.point[0].isFromRequest()) { + Request *r = SK.GetRequest(gs.point[0].request()); + int index = r->IndexOfPoint(gs.point[0]); + if((r->type == Request::CUBIC && (index > 1 && index < r->extraPoints + 2)) || + r->type == Request::CUBIC_PERIODIC) { + AddContextMenuItem("Remove Spline Point", CMNU_REMOVE_SPLINE_PT); + } + } + if(gs.entities == 1 && gs.entity[0].isFromRequest()) { + Request *r = SK.GetRequest(gs.entity[0].request()); + if(r->type == Request::CUBIC || r->type == Request::CUBIC_PERIODIC) { + Entity *e = SK.GetEntity(gs.entity[0]); + e->GetDistance(Point2d::From(x, y)); + addAfterPoint = e->dogd.data; + if(addAfterPoint == -1) oops(); + // Skip derivative point. + if(r->type == Request::CUBIC) addAfterPoint++; + AddContextMenuItem("Add Spline Point", CMNU_ADD_SPLINE_PT); } }