diff --git a/contrib/Netgen/nglib_addon.cpp b/contrib/Netgen/nglib_addon.cpp
index ad01859d3b88de4f8c4db0b353753b57df309d51..51527333faabc2fae202442aa7d5afb15dcdb197 100644
--- a/contrib/Netgen/nglib_addon.cpp
+++ b/contrib/Netgen/nglib_addon.cpp
@@ -41,7 +41,7 @@ class mystreambuf: public streambuf
   int overflow(int ch){ 
     if(index < 1023){
       txt[index] = ch;
-      if(txt[index] == '\n') txt[index] = ' ';
+      if(txt[index] == '\n' || txt[index] == '\r') txt[index] = ' ';
       if(!index && txt[0] == ' '){
 	// skip initial spaces
       }
@@ -59,10 +59,13 @@ void NgAddOn_Init()
   //mycout = &cout;
   //myerr = &cerr;
   //testout = new ofstream ("test.out");
-
-  mycout = new ostream(new mystreambuf());
-  myerr = new ostream(new mystreambuf());
-  testout = new ofstream("/dev/null");
+  static bool first = true;
+  if(first){
+    first = false;
+    mycout = new ostream(new mystreambuf());
+    myerr = new ostream(new mystreambuf());
+    testout = new ofstream("/dev/null");
+  }
 }
 
 // generates volume mesh from surface mesh, without optimization