Gui: Prevent crash when trying to delete pointer to BaseClass
This commit is contained in:
@@ -71,23 +71,17 @@ Workbench* WorkbenchManager::createWorkbench (const std::string& name, const std
|
||||
|
||||
if (!wb) {
|
||||
// try to create an instance now
|
||||
Base::BaseClass* base = static_cast<Base::BaseClass*>
|
||||
(Base::Type::createInstanceByName(className.c_str(),false));
|
||||
if (base) {
|
||||
if (!base->getTypeId().isDerivedFrom(Gui::Workbench::getClassTypeId())) {
|
||||
delete base;
|
||||
std::stringstream str;
|
||||
str << "'" << className << "' not a workbench type" << std::ends;
|
||||
throw Base::TypeError(str.str());
|
||||
}
|
||||
|
||||
wb = static_cast<Workbench*>(base);
|
||||
wb->setName(name);
|
||||
_workbenches[name] = wb;
|
||||
Base::Type type = Base::Type::getTypeIfDerivedFrom(className.c_str(), Workbench::getClassTypeId(), true);
|
||||
wb = static_cast<Workbench*>(type.createInstance());
|
||||
// createInstance could return a null pointer
|
||||
if (!wb) {
|
||||
std::stringstream str;
|
||||
str << "'" << className << "' not a workbench type" << std::ends;
|
||||
throw Base::TypeError(str.str());
|
||||
}
|
||||
else
|
||||
Base::Console().Log("WorkbenchManager::createWorkbench(): Can not create "
|
||||
"Workbench instance with type: %s\n",className.c_str());
|
||||
|
||||
wb->setName(name);
|
||||
_workbenches[name] = wb;
|
||||
}
|
||||
|
||||
return wb;
|
||||
|
||||
Reference in New Issue
Block a user