Index: code/branches/presentation3/src/modules/objects/Planet.cc
===================================================================
--- code/branches/presentation3/src/modules/objects/Planet.cc	(revision 7045)
+++ code/branches/presentation3/src/modules/objects/Planet.cc	(revision 7104)
@@ -70,5 +70,5 @@
         {
             Camera* activeCamera = CameraManager::getInstance().getActiveCamera();
-            if (activeCamera)
+            if (activeCamera && this->billboard_.getBillboardSet())
             {
                 float distance = this->getPosition().distance( activeCamera->getWorldPosition() );
@@ -89,49 +89,52 @@
     void Planet::init()
     {
-        float scaleFactor = this->getScale();
-
-#if OGRE_VERSION >= 0x010700
-        Ogre::Mesh::LodValueList distList;
-#else
-        Ogre::Mesh::LodDistanceList distList;
-#endif
-
-        distList.push_back(10.0f*scaleFactor);
-        distList.push_back(19.0f*scaleFactor);
-        distList.push_back(27.0f*scaleFactor);
-        distList.push_back(34.0f*scaleFactor);
-        distList.push_back(40.0f*scaleFactor);
-        distList.push_back(45.0f*scaleFactor);
-        distList.push_back(49.0f*scaleFactor);
-        distList.push_back(52.0f*scaleFactor);
-        distList.push_back(54.0f*scaleFactor);
-        distList.push_back(55.0f*scaleFactor);
-
-        float reductionValue = 0.2f;
-
-        this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, reductionValue);
-        billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->atmosphere_, Vector3(0,0,0));
-
-        this->attachOgreObject(this->billboard_.getBillboardSet());
-        this->billboard_.getBillboardSet()->setUseAccurateFacing(true);
-        this->setCastShadows(true);
-        this->billboard_.getBillboardSet()->setRenderQueueGroup(this->mesh_.getEntity()->getRenderQueueGroup());
-        this->mesh_.setCastShadows(true);
     }
 
     void Planet::changedMesh()
     {
-        if (this->mesh_.getEntity())
-            this->detachOgreObject(this->mesh_.getEntity());
+        if( GameMode::showsGraphics() )
+        {
+            if (this->mesh_.getEntity())
+                this->detachOgreObject(this->mesh_.getEntity());
 
-        this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_);
+            this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_);
 
-        if (this->mesh_.getEntity())
-        {
-            this->attachOgreObject(this->mesh_.getEntity());
-            this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
-            this->mesh_.setVisible(this->isVisible());
+            if (this->mesh_.getEntity())
+            {
+                this->attachOgreObject(this->mesh_.getEntity());
+                this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
+                this->mesh_.setVisible(this->isVisible());
+                
+                float scaleFactor = this->getScale();
+                
+    #if OGRE_VERSION >= 0x010700
+                Ogre::Mesh::LodValueList distList;
+    #else
+                Ogre::Mesh::LodDistanceList distList;
+    #endif
+                
+                distList.push_back(10.0f*scaleFactor);
+                distList.push_back(19.0f*scaleFactor);
+                distList.push_back(27.0f*scaleFactor);
+                distList.push_back(34.0f*scaleFactor);
+                distList.push_back(40.0f*scaleFactor);
+                distList.push_back(45.0f*scaleFactor);
+                distList.push_back(49.0f*scaleFactor);
+                distList.push_back(52.0f*scaleFactor);
+                distList.push_back(54.0f*scaleFactor);
+                distList.push_back(55.0f*scaleFactor);
+                
+                float reductionValue = 0.2f;
+                
+                this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, reductionValue);
+                billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->atmosphere_, Vector3(0,0,0));
+                
+                this->attachOgreObject(this->billboard_.getBillboardSet());
+                this->billboard_.getBillboardSet()->setUseAccurateFacing(true);
+                this->setCastShadows(true);
+                this->billboard_.getBillboardSet()->setRenderQueueGroup(this->mesh_.getEntity()->getRenderQueueGroup());
+                this->mesh_.setCastShadows(true);
+            }
         }
-        this->init();
     }
 
@@ -151,12 +154,9 @@
         SUPER(Planet, XMLPort, xmlelement, mode);
 
-        if (GameMode::showsGraphics())
-        {
-            XMLPortParam(Planet, "atmosphere", setAtmosphere, getAtmosphere, xmlelement, mode).defaultValues("planet/Atmosphere");
-            XMLPortParam(Planet, "atmospheresize", setAtmosphereSize, getAtmosphereSize, xmlelement,mode);
-            XMLPortParam(Planet, "imagesize", setImageSize, getImageSize, xmlelement,mode);
-            XMLPortParam(Planet, "mesh", setMeshSource, getMeshSource, xmlelement, mode);
-            XMLPortParam(Planet, "shadow", setCastShadows, getCastShadows, xmlelement, mode).defaultValues(true);
-        }
+        XMLPortParam(Planet, "atmosphere", setAtmosphere, getAtmosphere, xmlelement, mode).defaultValues("planet/Atmosphere");
+        XMLPortParam(Planet, "atmospheresize", setAtmosphereSize, getAtmosphereSize, xmlelement,mode);
+        XMLPortParam(Planet, "imagesize", setImageSize, getImageSize, xmlelement,mode);
+        XMLPortParam(Planet, "mesh", setMeshSource, getMeshSource, xmlelement, mode);
+        XMLPortParam(Planet, "shadow", setCastShadows, getCastShadows, xmlelement, mode).defaultValues(true);
     }
 
@@ -164,8 +164,9 @@
     {
         registerVariable(this->atmosphere_, VariableDirection::ToClient);
+        registerVariable(this->atmosphereSize, VariableDirection::ToClient);
+        registerVariable(this->imageSize, VariableDirection::ToClient);
+        // Note: the meshSrc should be synchronised after atmosphere and other values, because the meshSrc callback setts the atmosphere billboards
         registerVariable(this->meshSrc_, VariableDirection::ToClient, new NetworkCallback<Planet>(this, &Planet::changedMesh));
         registerVariable(this->bCastShadows_, VariableDirection::ToClient, new NetworkCallback<Planet>(this, &Planet::changedShadows));
-        registerVariable(this->atmosphereSize, VariableDirection::ToClient);
-        registerVariable(this->imageSize, VariableDirection::ToClient);
     }
 
