9cbb71d
# HG changeset patch
9cbb71d
# User Ian Chen <ichen@osrfoundation.org>
9cbb71d
# Date 1401470113 25200
9cbb71d
# Branch gazebo_3.1
9cbb71d
# Node ID eec4aa945cebb5c68858b3526875c41dd746aae7
9cbb71d
# Parent  839b2b92b357620f8cd7aa7854a07127f8775756
9cbb71d
# Parent  f4f20ee4a672ef19c1af9b99c7be6bfc434974d0
9cbb71d
Merged in issue_996_3.1 (pull request #1098)
9cbb71d
9cbb71d
Fix gzclient startup crash with ogre 1.9
9cbb71d
9cbb71d
diff --git a/cmake/SearchForStuff.cmake b/cmake/SearchForStuff.cmake
9cbb71d
--- a/cmake/SearchForStuff.cmake
9cbb71d
+++ b/cmake/SearchForStuff.cmake
9cbb71d
@@ -126,7 +126,7 @@
9cbb71d
   #################################################
9cbb71d
   # Find Simbody
9cbb71d
   set(SimTK_INSTALL_DIR ${SimTK_INSTALL_PREFIX})
9cbb71d
-  #list(APPEND CMAKE_MODULE_PATH ${SimTK_INSTALL_PREFIX}/share/cmake) 
9cbb71d
+  #list(APPEND CMAKE_MODULE_PATH ${SimTK_INSTALL_PREFIX}/share/cmake)
9cbb71d
   find_package(Simbody)
9cbb71d
   if (SIMBODY_FOUND)
9cbb71d
     set (HAVE_SIMBODY TRUE)
9cbb71d
@@ -154,17 +154,17 @@
9cbb71d
   if (NOT tinyxml_FOUND)
9cbb71d
       find_path (tinyxml_INCLUDE_DIRS tinyxml.h ${tinyxml_INCLUDE_DIRS} ENV CPATH)
9cbb71d
       find_library(tinyxml_LIBRARIES NAMES tinyxml)
9cbb71d
-      set (tinyxml_FAIL False) 
9cbb71d
+      set (tinyxml_FAIL False)
9cbb71d
       if (NOT tinyxml_INCLUDE_DIRS)
9cbb71d
         message (STATUS "Looking for tinyxml headers - not found")
9cbb71d
-        set (tinyxml_FAIL True) 
9cbb71d
+        set (tinyxml_FAIL True)
9cbb71d
       endif()
9cbb71d
       if (NOT tinyxml_LIBRARIES)
9cbb71d
         message (STATUS "Looking for tinyxml library - not found")
9cbb71d
-        set (tinyxml_FAIL True) 
9cbb71d
+        set (tinyxml_FAIL True)
9cbb71d
       endif()
9cbb71d
   endif()
9cbb71d
-        
9cbb71d
+
9cbb71d
   if (tinyxml_FAIL)
9cbb71d
     message (STATUS "Looking for tinyxml.h - not found")
9cbb71d
     BUILD_ERROR("Missing: tinyxml")
9cbb71d
@@ -231,13 +231,10 @@
9cbb71d
   endif ()
9cbb71d
 
9cbb71d
   pkg_check_modules(OGRE OGRE>=${MIN_OGRE_VERSION})
9cbb71d
-  # There are some runtime problems to solve with ogre-1.9. 
9cbb71d
-  # Please read gazebo issues: 994, 995, 996
9cbb71d
-  pkg_check_modules(MAX_VALID_OGRE OGRE<=1.8.9)
9cbb71d
+  # There are some runtime problems to solve with ogre-1.9.
9cbb71d
+  # Please read gazebo issues: 994, 995
9cbb71d
   if (NOT OGRE_FOUND)
9cbb71d
     BUILD_ERROR("Missing: Ogre3d version >=${MIN_OGRE_VERSION}(http://www.orge3d.org)")
9cbb71d
-  elseif (NOT MAX_VALID_OGRE_FOUND)
9cbb71d
-    BUILD_ERROR("Bad Ogre3d version: gazebo using ${OGRE_VERSION} ogre version has known bugs in runtime (issue #996). Please use 1.7 or 1.8 series")
9cbb71d
   else ()
9cbb71d
     set(ogre_ldflags ${ogre_ldflags} ${OGRE_LDFLAGS})
9cbb71d
     set(ogre_include_dirs ${ogre_include_dirs} ${OGRE_INCLUDE_DIRS})
9cbb71d
@@ -372,8 +369,8 @@
9cbb71d
 
9cbb71d
   #################################################
9cbb71d
   # Find bullet
9cbb71d
-  # First and preferred option is to look for bullet standard pkgconfig, 
9cbb71d
-  # so check it first. if it is not present, check for the OSRF 
9cbb71d
+  # First and preferred option is to look for bullet standard pkgconfig,
9cbb71d
+  # so check it first. if it is not present, check for the OSRF
9cbb71d
   # custom bullet2.82.pc file
9cbb71d
   pkg_check_modules(BULLET bullet>=2.82)
9cbb71d
   if (NOT BULLET_FOUND)
9cbb71d
@@ -453,16 +450,16 @@
9cbb71d
 #find_path(QWT_INCLUDE_DIR NAMES qwt.h PATHS
9cbb71d
 #  /usr/include
9cbb71d
 #  /usr/local/include
9cbb71d
-#  "$ENV{LIB_DIR}/include" 
9cbb71d
-#  "$ENV{INCLUDE}" 
9cbb71d
+#  "$ENV{LIB_DIR}/include"
9cbb71d
+#  "$ENV{INCLUDE}"
9cbb71d
 #  PATH_SUFFIXES qwt-qt4 qwt qwt5
9cbb71d
 #  )
9cbb71d
 #
9cbb71d
-#find_library(QWT_LIBRARY NAMES qwt qwt6 qwt5 PATHS 
9cbb71d
+#find_library(QWT_LIBRARY NAMES qwt qwt6 qwt5 PATHS
9cbb71d
 #  /usr/lib
9cbb71d
 #  /usr/local/lib
9cbb71d
-#  "$ENV{LIB_DIR}/lib" 
9cbb71d
-#  "$ENV{LIB}/lib" 
9cbb71d
+#  "$ENV{LIB_DIR}/lib"
9cbb71d
+#  "$ENV{LIB}/lib"
9cbb71d
 #  )
9cbb71d
 #
9cbb71d
 #if (QWT_INCLUDE_DIR AND QWT_LIBRARY)
9cbb71d
diff --git a/gazebo/rendering/Light.cc b/gazebo/rendering/Light.cc
9cbb71d
--- a/gazebo/rendering/Light.cc
9cbb71d
+++ b/gazebo/rendering/Light.cc
9cbb71d
@@ -53,6 +53,9 @@
9cbb71d
   if (this->light)
9cbb71d
     this->scene->GetManager()->destroyLight(this->GetName());
9cbb71d
 
9cbb71d
+  this->scene->GetManager()->destroyEntity(
9cbb71d
+      this->GetName() + "_selection_sphere");
9cbb71d
+
9cbb71d
   this->visual->DeleteDynamicLine(this->line);
9cbb71d
   this->scene->RemoveVisual(this->visual);
9cbb71d
   this->visual.reset();
9cbb71d
@@ -276,11 +279,14 @@
9cbb71d
     // Make sure the unit_sphere has been inserted.
9cbb71d
     this->visual->InsertMesh("unit_sphere");
9cbb71d
 
9cbb71d
+    Ogre::Entity *ent =
9cbb71d
+        visSceneNode->getCreator()->createEntity(this->GetName() +
9cbb71d
+        "_selection_sphere", "unit_sphere");
9cbb71d
+
9cbb71d
+    ent->setMaterialName("Gazebo/White");
9cbb71d
+
9cbb71d
     // Create the selection object.
9cbb71d
-    Ogre::MovableObject *obj = static_cast<Ogre::MovableObject*>
9cbb71d
-      (visSceneNode->getCreator()->createEntity(this->GetName() +
9cbb71d
-                                                "_selection_sphere",
9cbb71d
-                                                "unit_sphere"));
9cbb71d
+    Ogre::MovableObject *obj = static_cast<Ogre::MovableObject*>(ent);
9cbb71d
 
9cbb71d
     // Attach the selection object to the light visual
9cbb71d
     visSceneNode->attachObject(obj);
9cbb71d
diff --git a/gazebo/rendering/RenderEngine.cc b/gazebo/rendering/RenderEngine.cc
9cbb71d
--- a/gazebo/rendering/RenderEngine.cc
9cbb71d
+++ b/gazebo/rendering/RenderEngine.cc
9cbb71d
@@ -66,6 +66,10 @@
9cbb71d
   this->logManager = NULL;
9cbb71d
   this->root = NULL;
9cbb71d
 
9cbb71d
+#if (OGRE_VERSION >= ((1 << 16) | (9 << 8) | 0))
9cbb71d
+  this->overlaySystem = NULL;
9cbb71d
+#endif
9cbb71d
+
9cbb71d
   this->dummyDisplay = NULL;
9cbb71d
 
9cbb71d
   this->initialized = false;
9cbb71d
@@ -116,10 +120,12 @@
9cbb71d
       gzthrow("Unable to create an Ogre rendering environment, no Root ");
9cbb71d
     }
9cbb71d
 
9cbb71d
-#if OGRE_VERSION_MAJR > 1 || OGRE_VERSION_MINOR >= 9
9cbb71d
-    // Must be created after this->root, but before this->root is
9cbb71d
-    // initialized.
9cbb71d
-    this->overlaySystem = new Ogre::OverlaySystem();
9cbb71d
+#if (OGRE_VERSION >= ((1 << 16) | (9 << 8) | 0))
9cbb71d
+    // OgreOverlay is a component on its own in ogre 1.9 so must manually
9cbb71d
+    // initialize it. Must be created after this->root, but before this->root
9cbb71d
+    // is initialized.
9cbb71d
+    if (!this->overlaySystem)
9cbb71d
+      this->overlaySystem = new Ogre::OverlaySystem();
9cbb71d
 #endif
9cbb71d
 
9cbb71d
     // Load all the plugins
9cbb71d
@@ -326,6 +332,11 @@
9cbb71d
     this->RemoveScene(this->scenes.front()->GetName());
9cbb71d
   }
9cbb71d
 
9cbb71d
+#if (OGRE_VERSION >= ((1 << 16) | (9 << 8) | 0))
9cbb71d
+  delete this->overlaySystem;
9cbb71d
+  this->overlaySystem = NULL;
9cbb71d
+#endif
9cbb71d
+
9cbb71d
   // TODO: this was causing a segfault. Need to debug, and put back in
9cbb71d
   if (this->root)
9cbb71d
   {
9cbb71d
@@ -768,7 +779,7 @@
9cbb71d
   return this->windowManager;
9cbb71d
 }
9cbb71d
 
9cbb71d
-#if OGRE_VERSION_MAJR > 1 || OGRE_VERSION_MINOR >= 9
9cbb71d
+#if (OGRE_VERSION >= ((1 << 16) | (9 << 8) | 0))
9cbb71d
 /////////////////////////////////////////////////
9cbb71d
 Ogre::OverlaySystem *RenderEngine::GetOverlaySystem() const
9cbb71d
 {
9cbb71d
diff --git a/gazebo/rendering/Visual.cc b/gazebo/rendering/Visual.cc
9cbb71d
--- a/gazebo/rendering/Visual.cc
9cbb71d
+++ b/gazebo/rendering/Visual.cc
9cbb71d
@@ -776,7 +776,7 @@
9cbb71d
   this->InsertMesh(_meshName, _subMesh, _centerSubmesh);
9cbb71d
 
9cbb71d
   obj = (Ogre::MovableObject*)
9cbb71d
-    (this->dataPtr->sceneNode->getCreator()->createEntity(objName, meshName));
9cbb71d
+      (this->dataPtr->sceneNode->getCreator()->createEntity(objName, meshName));
9cbb71d
 
9cbb71d
   this->AttachObject(obj);
9cbb71d
   return obj;
9cbb71d
@@ -2084,6 +2084,10 @@
9cbb71d
         rendering::Material::Update(material);
9cbb71d
         ogreSubMesh->setMaterialName(material->GetName());
9cbb71d
       }
9cbb71d
+      else
9cbb71d
+      {
9cbb71d
+        ogreSubMesh->setMaterialName("Gazebo/White");
9cbb71d
+      }
9cbb71d
 
9cbb71d
       // Unlock
9cbb71d
       vBuf->unlock();
9cbb71d