Browse Source

merge

Former-commit-id: 042d0d0fb74b6825ac1dbe930f0127ddde5c14f6
Alec Jacobson (jalec 11 years ago
parent
commit
ca2d8d15cb

+ 1 - 1
examples/principal_curvature/curvature.REMOVED.git-id

@@ -1 +1 @@
-3b29fb167099af338cc72c6c7ac90ac23d8e2948
+71a9dea1fc763a1dc5caa543becdceaa9a7e391a

+ 17 - 7
include/igl/ReAntTweakBar.cpp

@@ -19,6 +19,7 @@ IGL_INLINE TwType igl::ReTwDefineEnum(
   const TwEnumVal *enumValues, 
   unsigned int nbValues)
 {
+  using namespace std;
   // copy enum valus into vector
   std::vector<TwEnumVal> enum_vals;
   enum_vals.resize(nbValues);
@@ -30,6 +31,7 @@ IGL_INLINE TwType igl::ReTwDefineEnum(
 
   ReTw_custom_types[type] = 
     std::pair<const char *,std::vector<TwEnumVal> >(name,enum_vals);
+
   return type;
 }
 
@@ -64,10 +66,17 @@ IGL_INLINE TwType igl::ReTwDefineEnum(
     for( int i=0; i<(int)Labels.size(); i++ )
     {
         Vals[i].Value = i;
-        Vals[i].Label = Labels[i].c_str();
+        // Wrong:
+        //Vals[i].Label = Labels[i].c_str();
+        // Allocate char on heap
+        // http://stackoverflow.com/a/10050258/148668
+        char * c_label = new char[Labels[i].length()+1];
+        std::strcpy(c_label, Labels[i].c_str());
+        Vals[i].Label = c_label;
     }
 
-    return ReTwDefineEnum(_Name, Vals.empty() ? NULL : &(Vals[0]), (unsigned int)Vals.size());
+    const TwType type = ReTwDefineEnum(_Name, Vals.empty() ? NULL : &(Vals[0]), (unsigned int)Vals.size());
+    return type;
   }
 }
 
@@ -416,14 +425,15 @@ IGL_INLINE std::string igl::ReTwBar::get_value_as_string(
       }
     default:
       {
-        std::map<TwType,std::pair<const char *,std::vector<TwEnumVal> > >::iterator iter = 
+        using namespace std;
+        std::map<TwType,std::pair<const char *,std::vector<TwEnumVal> > >::const_iterator iter = 
           ReTw_custom_types.find(type);
         if(iter != ReTw_custom_types.end())
         {
           sstr << (*iter).second.first << " ";
           int enum_val = *(static_cast<int*>(var));
           // try find display name for enum value
-          std::vector<TwEnumVal>::iterator eit = (*iter).second.second.begin();
+          std::vector<TwEnumVal>::const_iterator eit = (*iter).second.second.begin();
           bool found = false;
           for(;eit<(*iter).second.second.end();eit++)
           {
@@ -523,7 +533,7 @@ IGL_INLINE bool igl::ReTwBar::type_from_string(const char *type_str, TwType & ty
   }
 
   // then check custom types
-  std::map<TwType,std::pair<const char *,std::vector<TwEnumVal> > >::iterator iter = 
+  std::map<TwType,std::pair<const char *,std::vector<TwEnumVal> > >::const_iterator iter = 
     ReTw_custom_types.begin();
   for(;iter != ReTw_custom_types.end(); iter++)
   {
@@ -680,11 +690,11 @@ bool igl::ReTwBar::set_value_from_string(
       }
     default:
       // Try to find type in custom enum types
-      std::map<TwType,std::pair<const char *,std::vector<TwEnumVal> > >::iterator iter = 
+      std::map<TwType,std::pair<const char *,std::vector<TwEnumVal> > >::const_iterator iter = 
         ReTw_custom_types.find(type);
       if(iter != ReTw_custom_types.end())
       {
-        std::vector<TwEnumVal>::iterator eit = (*iter).second.second.begin();
+        std::vector<TwEnumVal>::const_iterator eit = (*iter).second.second.begin();
         bool found = false;
         for(;eit<(*iter).second.second.end();eit++)
         {