Gui: Prevent crash when trying to delete pointer to BaseClass

This commit is contained in:
marioalexis
2022-05-22 02:43:55 -03:00
committed by wwmayer
parent e76e4acb0f
commit c00699b15d
3 changed files with 22 additions and 33 deletions

View File

@@ -1445,18 +1445,13 @@ bool View3DInventorViewer::hasAxisCross(void)
void View3DInventorViewer::setNavigationType(Base::Type t)
{
if (t.isBad())
return;
if (this->navigation && this->navigation->getTypeId() == t)
return; // nothing to do
Base::BaseClass* base = static_cast<Base::BaseClass*>(t.createInstance());
if (!base)
return;
if (!base->getTypeId().isDerivedFrom(NavigationStyle::getClassTypeId())) {
delete base;
Base::Type type = Base::Type::getTypeIfDerivedFrom(t.getName(), NavigationStyle::getClassTypeId());
NavigationStyle* ns = static_cast<NavigationStyle*>(type.createInstance());
// createInstance could return a null pointer
if (!ns) {
#if FC_DEBUG
SoDebugError::postWarning("View3DInventorViewer::setNavigationType",
"Navigation object must be of type NavigationStyle.");
@@ -1464,7 +1459,6 @@ void View3DInventorViewer::setNavigationType(Base::Type t)
return;
}
NavigationStyle* ns = static_cast<NavigationStyle*>(base);
if (this->navigation) {
ns->operator = (*this->navigation);
delete this->navigation;