Index: Geo/GFaceCompound.cpp
===================================================================
--- Geo/GFaceCompound.cpp	(revision 22287)
+++ Geo/GFaceCompound.cpp	(working copy)
@@ -267,7 +267,7 @@
   ePoly.erase(ite);
 
   while(!ePoly.empty()){
-    ite = ePoly.begin() ;
+    std::vector<MEdge>::iterator ite = ePoly.begin() ;
     while(ite != ePoly.end()){
       MVertex *vB = ite->getVertex(0);
       MVertex *vE = ite->getVertex(1);
@@ -2766,54 +2766,55 @@
 
 void GFaceCompound::coherenceNormals()
 {
-  Msg::Info("Re-orient all %d face normals coherently", getNumMeshElements());
+  if (getNumMeshElements() > 0) {
+	  Msg::Info("Re-orient all %d face normals coherently", getNumMeshElements());
+	  std::map<MEdge, std::set<MElement*>, Less_Edge > edge2elems;
+	  for(unsigned int i = 0; i <  getNumMeshElements(); i++){
+		MElement *t =  getMeshElement(i);
+		for (int j = 0; j <  t->getNumEdges(); j++){
+		  MEdge me = t->getEdge(j);
+		  std::map<MEdge, std::set<MElement*, std::less<MElement*> >,
+			Less_Edge >::iterator it = edge2elems.find(me);
+		  if (it == edge2elems.end()) {
+			std::set<MElement*, std::less<MElement*> > mySet;
+			mySet.insert(t);
+			edge2elems.insert(std::make_pair(me, mySet));
+		  }
+		  else{
+			std::set<MElement*, std::less<MElement*> > mySet = it->second;
+			mySet.insert(t);
+			it->second = mySet;
+		  }
+		}
+	  }
 
-  std::map<MEdge, std::set<MElement*>, Less_Edge > edge2elems;
-  for(unsigned int i = 0; i <  getNumMeshElements(); i++){
-    MElement *t =  getMeshElement(i);
-    for (int j = 0; j <  t->getNumEdges(); j++){
-      MEdge me = t->getEdge(j);
-      std::map<MEdge, std::set<MElement*, std::less<MElement*> >,
-        Less_Edge >::iterator it = edge2elems.find(me);
-      if (it == edge2elems.end()) {
-        std::set<MElement*, std::less<MElement*> > mySet;
-        mySet.insert(t);
-        edge2elems.insert(std::make_pair(me, mySet));
-      }
-      else{
-        std::set<MElement*, std::less<MElement*> > mySet = it->second;
-        mySet.insert(t);
-        it->second = mySet;
-      }
-    }
+	  std::set<MElement* , std::less<MElement*> > touched;
+	  int iE, si, iE2, si2;
+	  touched.insert(getMeshElement(0));
+	  while(touched.size() != getNumMeshElements()){
+		for(unsigned int i = 0; i < getNumMeshElements(); i++){
+		  MElement *t = getMeshElement(i);
+		  std::set<MElement*, std::less<MElement*> >::iterator it2 = touched.find(t);
+		  if(it2 != touched.end()){
+			for (int j = 0; j <  t->getNumEdges(); j++){
+			  MEdge me = t->getEdge(j);
+			  t->getEdgeInfo(me, iE,si);
+			  std::map<MEdge, std::set<MElement*>, Less_Edge >::iterator it =
+				edge2elems.find(me);
+			  std::set<MElement*, std::less<MElement*> > mySet = it->second;
+			  for(std::set<MElement*, std::less<MElement*> >::iterator itt = mySet.begin();
+				  itt != mySet.end(); itt++){
+				if (*itt != t){
+				  (*itt)->getEdgeInfo(me,iE2,si2);
+				  if(si == si2)  (*itt)->reverse();
+				  touched.insert(*itt);
+				}
+			  }
+			}
+		  }
+		}
+	  }
   }
-
-  std::set<MElement* , std::less<MElement*> > touched;
-  int iE, si, iE2, si2;
-  touched.insert(getMeshElement(0));
-  while(touched.size() != getNumMeshElements()){
-    for(unsigned int i = 0; i < getNumMeshElements(); i++){
-      MElement *t = getMeshElement(i);
-      std::set<MElement*, std::less<MElement*> >::iterator it2 = touched.find(t);
-      if(it2 != touched.end()){
-        for (int j = 0; j <  t->getNumEdges(); j++){
-          MEdge me = t->getEdge(j);
-          t->getEdgeInfo(me, iE,si);
-          std::map<MEdge, std::set<MElement*>, Less_Edge >::iterator it =
-            edge2elems.find(me);
-          std::set<MElement*, std::less<MElement*> > mySet = it->second;
-          for(std::set<MElement*, std::less<MElement*> >::iterator itt = mySet.begin();
-              itt != mySet.end(); itt++){
-            if (*itt != t){
-              (*itt)->getEdgeInfo(me,iE2,si2);
-              if(si == si2)  (*itt)->reverse();
-              touched.insert(*itt);
-            }
-          }
-        }
-      }
-    }
-  }
 }
 
 void GFaceCompound::buildAllNodes() const
Index: Geo/GModel.cpp
===================================================================
--- Geo/GModel.cpp	(revision 22287)
+++ Geo/GModel.cpp	(working copy)
@@ -1896,7 +1896,7 @@
   Msg::StatusBar(true, "Creating topology from mesh...");
   double t1 = Cpu();
 
-  removeDuplicateMeshVertices(CTX::instance()->geom.tolerance);
+  //removeDuplicateMeshVertices(CTX::instance()->geom.tolerance);
   makeDiscreteRegionsSimplyConnected();
   makeDiscreteFacesSimplyConnected();
 
Index: Geo/GModelIO_STL.cpp
===================================================================
--- Geo/GModelIO_STL.cpp	(revision 22287)
+++ Geo/GModelIO_STL.cpp	(working copy)
@@ -183,6 +183,20 @@
 int GModel::writeSTL(const std::string &name, bool binary, bool saveAll,
                      double scalingFactor)
 {
+  if(noPhysicalGroups()) saveAll = true;
+
+  unsigned int nfacets = 0;
+  for(fiter it = firstFace(); it != lastFace(); ++it){
+	  if(saveAll || (*it)->physicals.size()){
+		nfacets += (*it)->triangles.size() + 2 * (*it)->quadrangles.size();
+	  }
+  }
+
+  if (nfacets == 0) {
+	Msg::Error("No points to write in file '%s'", name.c_str());
+    return 0;
+  }
+
   FILE *fp = Fopen(name.c_str(), binary ? "wb" : "w");
   if(!fp){
     Msg::Error("Unable to open file '%s'", name.c_str());
@@ -189,8 +203,6 @@
     return 0;
   }
 
-  if(noPhysicalGroups()) saveAll = true;
-
   if(!binary){
     fprintf(fp, "solid Created by Gmsh\n");
   }
@@ -198,12 +210,6 @@
     char header[80];
     strncpy(header, "Created by Gmsh", 80);
     fwrite(header, sizeof(char), 80, fp);
-    unsigned int nfacets = 0;
-    for(fiter it = firstFace(); it != lastFace(); ++it){
-      if(saveAll || (*it)->physicals.size()){
-        nfacets += (*it)->triangles.size() + 2 * (*it)->quadrangles.size();
-      }
-    }
     fwrite(&nfacets, sizeof(unsigned int), 1, fp);
   }
 
Index: Geo/GModelIO_VTK.cpp
===================================================================
--- Geo/GModelIO_VTK.cpp	(revision 22287)
+++ Geo/GModelIO_VTK.cpp	(working copy)
@@ -18,6 +18,16 @@
 int GModel::writeVTK(const std::string &name, bool binary, bool saveAll,
                      double scalingFactor, bool bigEndian)
 {
+  // get the number of vertices and index the vertices in a continuous
+  // sequence
+  if(noPhysicalGroups()) saveAll = true;
+
+  int numVertices = indexMeshVertices(saveAll);
+  if (numVertices == 0) {
+	Msg::Error("No points to write in file '%s'", name.c_str());
+    return 0;
+  }
+
   FILE *fp = Fopen(name.c_str(), binary ? "wb" : "w");
   if(!fp){
     Msg::Error("Unable to open file '%s'", name.c_str());
@@ -24,13 +34,7 @@
     return 0;
   }
 
-  if(noPhysicalGroups()) saveAll = true;
-
-  // get the number of vertices and index the vertices in a continuous
-  // sequence
-  int numVertices = indexMeshVertices(saveAll);
-
-  fprintf(fp, "# vtk DataFile Version 2.0\n");
+   fprintf(fp, "# vtk DataFile Version 2.0\n");
   fprintf(fp, "%s, Created by Gmsh\n", getName().c_str());
   if(binary)
     fprintf(fp, "BINARY\n");
Index: Mesh/BackgroundMesh3D.cpp
===================================================================
--- Mesh/BackgroundMesh3D.cpp	(revision 22287)
+++ Mesh/BackgroundMesh3D.cpp	(working copy)
@@ -534,7 +534,7 @@
     //               nb_local_iterations.end(),0))/nb_local_iterations.size() << endl;
 
     //if (debug){
-    double temp = log10(Niter);
+    double temp = log10((double)Niter);
     stringstream ss;
     ss << "cf_iter_" << setfill('0') << setw ((int)(ceil(temp))) << iIter << ".pos";
     exportCrossField(ss.str().c_str());
Index: Mesh/meshGFace.cpp
===================================================================
--- Mesh/meshGFace.cpp	(revision 22287)
+++ Mesh/meshGFace.cpp	(working copy)
@@ -2514,7 +2514,8 @@
   multiscalePartition *msp = new multiscalePartition(elements, abs(gf->nbSplit),
 						     method, allowType);
 
-  int NF = msp->getNumberOfParts();
+  int NF = msp->getNumberOfParts(); 
+  
   int numv = gf->model()->getMaxElementaryNumber(0) + 1;
   int nume = gf->model()->getMaxElementaryNumber(1) + 1;
   int numf = gf->model()->getMaxElementaryNumber(2) + 1;
Index: Mesh/multiscalePartition.cpp
===================================================================
--- Mesh/multiscalePartition.cpp	(revision 22287)
+++ Mesh/multiscalePartition.cpp	(working copy)
@@ -242,7 +242,9 @@
   for (unsigned int i = 0; i < elements.size(); ++i){
     MElement *e = elements[i];
     int part = e->getPartition();
-    regions[part-1].push_back(e);
+	if (part > 0) {
+		regions[part-1].push_back(e);
+	}
   }
 
   std::vector<std::vector<MElement*> > allRegions;
Index: contrib/HighOrderMeshOptimizer/CADDistances.cpp
===================================================================
--- contrib/HighOrderMeshOptimizer/CADDistances.cpp	(revision 22287)
+++ contrib/HighOrderMeshOptimizer/CADDistances.cpp	(working copy)
@@ -369,7 +369,7 @@
     const int nV = l->getNumVertices();
     for (int i=0; i<nV; ++i) xyz.push_back(l->getVertex(i)->point());
     parametricLineNodalBasis l2(basis, xyz);
-    int minDepth = std::ceil(std::log(nV)/std::log(2));
+    int minDepth = std::ceil(std::log((double)nV)/std::log((double)2));
     l2.discretize(dpts2, ts2, tol, minDepth, 10*minDepth);
   }
   oversample(dpts2, tol);
Index: contrib/MeshOptimizer/MeshOptPatch.cpp
===================================================================
--- contrib/MeshOptimizer/MeshOptPatch.cpp	(revision 22287)
+++ contrib/MeshOptimizer/MeshOptPatch.cpp	(working copy)
@@ -107,7 +107,7 @@
     _bndEl2FV.resize(nBndElts);
     int iBndEl = 0;
     bool unknownVert = false;
-    for(std::set<MElement*>::iterator it = bndEls.begin();
+    for(std::set<MElement*>::iterator it = ((std::set<MElement*>)bndEls).begin();
         it != bndEls.end(); ++it, ++iBndEl) {
       MElement* bndEl = *it;
       _bndEl[iBndEl] = bndEl;
Index: contrib/MeshOptimizer/MeshOptimizer.cpp
===================================================================
--- contrib/MeshOptimizer/MeshOptimizer.cpp	(revision 22287)
+++ contrib/MeshOptimizer/MeshOptimizer.cpp	(working copy)
@@ -353,7 +353,7 @@
 void getAdjacentBndElts(const elElMap &el2BndEl, const elEntMap &bndEl2Ent,
                         const elSet &elts, elSet &bndElts, MeshOptParameters &par)
 {
-  for (elSetIter itEl=elts.begin(); itEl!=elts.end(); itEl++) {
+  for (elSetIter itEl=((elSet)elts).begin(); itEl!=elts.end(); itEl++) {
     elElMap::const_iterator itBndEl = el2BndEl.find(*itEl);
     if (itBndEl != el2BndEl.end()) {
       MElement* bndEl = itBndEl->second;
