From 0c4eaa8b29521e714b158bb6439f4d4bac86e704 Mon Sep 17 00:00:00 2001 From: Richard Harrison Date: Sat, 20 May 2017 13:40:02 +0200 Subject: [PATCH] Canvas exception during re-init. Add defensive logic to ensure that a null pointer isn't dereferenced. This happened to me once or twice during a reinit (Location/Position In Air to the current position). It may be related to the model, but in any case the code needs to ensure that the static cast failure is handled correctly. --- src/Canvas/canvas_mgr.cxx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Canvas/canvas_mgr.cxx b/src/Canvas/canvas_mgr.cxx index 6646b7762..0869d5d3f 100644 --- a/src/Canvas/canvas_mgr.cxx +++ b/src/Canvas/canvas_mgr.cxx @@ -137,6 +137,10 @@ CanvasMgr::getCanvasTexId(const simgear::canvas::CanvasPtr& canvas) const //---------------------------------------------------------------------------- void CanvasMgr::handleModelReinit(SGPropertyNode*) { - for(size_t i = 0; i < _elements.size(); ++i) - static_cast(_elements[i].get())->reloadPlacements("object"); + for (size_t i = 0; i < _elements.size(); ++i) + { + sc::Canvas* element = static_cast(_elements[i].get()); + if (element) + element->reloadPlacements("object"); + } }