From dd54f6938ebb23bc050db9c7b87b6e8d25b1ed92 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Wed, 25 Apr 2012 21:08:37 +0200 Subject: [PATCH] #717: Disabling advanced weather crashes the sim Protect from a NULL-pointer segfault in SGCloudField::removeCloudFromTree when disabling advanced weather (may just fix a symptom). --- simgear/scene/sky/cloudfield.cxx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/simgear/scene/sky/cloudfield.cxx b/simgear/scene/sky/cloudfield.cxx index f3abdc12..1d9ae9ea 100644 --- a/simgear/scene/sky/cloudfield.cxx +++ b/simgear/scene/sky/cloudfield.cxx @@ -178,7 +178,7 @@ SGCloudField::SGCloudField() : } SGCloudField::~SGCloudField() { - } +} void SGCloudField::clear(void) { @@ -208,7 +208,7 @@ void SGCloudField::applyVisAndLoDRange(void) bool SGCloudField::addCloud(float lon, float lat, float alt, int index, osg::ref_ptr geode) { return addCloud(lon, lat, alt, 0.0f, 0.0f, index, geode); - } +} bool SGCloudField::addCloud(float lon, float lat, float alt, float x, float y, int index, osg::ref_ptr geode) { // If this cloud index already exists, don't replace it. @@ -220,11 +220,16 @@ bool SGCloudField::addCloud(float lon, float lat, float alt, float x, float y, i addCloudToTree(transform, lon, lat, alt, x, y); cloud_hash[index] = transform; return true; - } - +} + // Remove a give cloud from inside the tree, without removing it from the cloud hash void SGCloudField::removeCloudFromTree(osg::ref_ptr transform) { + if (transform == 0) + { + // Ooops! + return; + } osg::ref_ptr lodnode = transform->getParent(0); lodnode->removeChild(transform); cloudcount--; @@ -236,8 +241,8 @@ void SGCloudField::removeCloudFromTree(osg::ref_ptrremoveChild(lodnode); lodcount--; - if (lodnode1->getNumChildren() == 0) { - impostornode->removeChild(lodnode1); + if (lodnode1->getNumChildren() == 0) { + impostornode->removeChild(lodnode1); placed_root->removeChild(impostornode); impostorcount--; } -- 2.39.5