TD: Fix crash on selecting 3D edge for dimension
Unlike in the bug description of issue 19654 the user doesn't have to preselect an edge in the 3D view but first start the dimension command and then select an edge. This commit adds some security checks to TechDrawHandler::quit(), TechDrawHandler::getPage() and TDHandlerDimension::onSelectionChanged() to be on the safe side that no null pointers are dereferenced. But the ultimative fix for this whole problem is to change activateHandler() and immediately delete the passed TechDrawHandler if it fails to find the appropriate QGVPage. This is needed as otherwise the handler behaves like a ghost object that affects the selection mechanism and disallows to select anything in the 3D view or the tree view. Fixes issue 19654
This commit is contained in:
@@ -120,6 +120,7 @@ void positionDimText(DrawViewDimension* dim, int indexOffset = 0);
|
||||
|
||||
void activateHandler(TechDrawHandler* newHandler)
|
||||
{
|
||||
std::unique_ptr<TechDrawHandler> ptr(newHandler);
|
||||
auto* mdi = qobject_cast<MDIViewPage*>(Gui::getMainWindow()->activeWindow());
|
||||
if (!mdi) {
|
||||
return;
|
||||
@@ -134,7 +135,7 @@ void activateHandler(TechDrawHandler* newHandler)
|
||||
if (!viewPage) {
|
||||
return;
|
||||
}
|
||||
viewPage->activateHandler(newHandler);
|
||||
viewPage->activateHandler(ptr.release());
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -517,8 +518,12 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
App::Document* pageDoc = nullptr;
|
||||
if (auto page = getPage()) {
|
||||
pageDoc = page->getDocument();
|
||||
}
|
||||
if (msg.Object.getObjectName().empty()
|
||||
|| msg.Object.getDocument() != getPage()->getDocument()) {
|
||||
|| (msg.Object.getDocument() != pageDoc)) {
|
||||
if (msg.Type == Gui::SelectionChanges::AddSelection) {
|
||||
Gui::Selection().rmvSelection(msg.pDocName, msg.pObjectName, msg.pSubName);
|
||||
}
|
||||
|
||||
@@ -109,7 +109,9 @@ void TechDrawHandler::mouseReleaseEvent(QMouseEvent* event)
|
||||
|
||||
void TechDrawHandler::quit()
|
||||
{
|
||||
viewPage->deactivateHandler();
|
||||
if (viewPage) {
|
||||
viewPage->deactivateHandler();
|
||||
}
|
||||
}
|
||||
|
||||
QWidget* TechDrawHandler::getCursorWidget()
|
||||
@@ -127,5 +129,5 @@ void TechDrawHandler::setWidgetCursor(QCursor cursor)
|
||||
|
||||
TechDraw::DrawPage* TechDrawHandler::getPage()
|
||||
{
|
||||
return viewPage->getDrawPage();
|
||||
}
|
||||
return viewPage ? viewPage->getDrawPage() : nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user