I'm trying to implement a function in the app layer that returns a pointer to the human view for convenience.
However, when I use that function, it causes the game logic's update function to crash in the next iteration. This is the function:
std::shared_ptr<BaseHumanView> BaseAppLayer::getHumanView()
{
for (auto view : logic->getViews()) // getViews() returns a std::list<IGameView> by reference
{
if (view->getType() == IGameView::VIEW_HUMAN)
{
BaseHumanView* humanView = dynamic_cast<BaseHumanView*>(view.get()); // convert IGameView* to BaseHumanView*
return std::shared_ptr<BaseHumanView>(humanView);
}
}
...
The function seems to work properly, but during the next tick, BaseGameLogic::update(), its crashing with a segmentation fault at this portion:
for (auto& viewPtr : views)
{
viewPtr->onUpdate();
}
I suspect that the getHumanView() function is doing something that I may not be aware of, maybe during the type conversion. Anyone knows what's going on?
However, when I use that function, it causes the game logic's update function to crash in the next iteration. This is the function:
std::shared_ptr<BaseHumanView> BaseAppLayer::getHumanView()
{
for (auto view : logic->getViews()) // getViews() returns a std::list<IGameView> by reference
{
if (view->getType() == IGameView::VIEW_HUMAN)
{
BaseHumanView* humanView = dynamic_cast<BaseHumanView*>(view.get()); // convert IGameView* to BaseHumanView*
return std::shared_ptr<BaseHumanView>(humanView);
}
}
...
The function seems to work properly, but during the next tick, BaseGameLogic::update(), its crashing with a segmentation fault at this portion:
for (auto& viewPtr : views)
{
viewPtr->onUpdate();
}
I suspect that the getHumanView() function is doing something that I may not be aware of, maybe during the type conversion. Anyone knows what's going on?