The following line gives seg fault on
Code: Select all
dynamic_cast<std::remove_pointer_t<T> *>(guiElement);
Code: Select all
std::remove_pointer_t<T> * getGuiElement(int in_id)
{
//check that T is a valid type to try to upcast during compile time.
static_assert(std::is_base_of<irr::gui::IGUIElement, std::remove_pointer_t<T>>::value,
"T must inherit irr::gui::IGUIElement");
if (!_guiEnv)
{
//LOG(ERROR) << "gui environment is null";
throw std::runtime_error("menu was not set correctly!");
}
if (!_guiEnv->getRootGUIElement())
{
throw std::runtime_error("no gui root element");
}
auto guiElement = _guiEnv->getRootGUIElement()->getElementFromId(in_id);
if (!guiElement)
{
throw std::runtime_error("Could not find gui element");
}
auto requestedElement = dynamic_cast<std::remove_pointer_t<T> *>(guiElement);
if (!requestedElement)
{
throw std::runtime_error("Failed dynamic casting of GUI element");
}
return requestedElement;
}
Code: Select all
getGuiElement<irr::gui::IGUISpinBox>(MenuElement::MazeNumOfAI)->getValue();
Code: Select all
auto spinBox = _guiEnv->addSpinBox(L"Number of AI players", irr::core::recti(elementPosition, elementSize),true,nullptr,MenuElement::MazeNumOfAI);
spinBox->setDecimalPlaces(0);
spinBox->setRange(0.0f, 10.0f);
spinBox->setValue(3.0f);
_gameSettingsElements.push_back(spinBox);