]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
fix invalid memory access caused by undefined order of construction of static members...
authorheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 23 Jan 2014 17:26:42 +0000 (17:26 +0000)
committerheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 23 Jan 2014 17:26:42 +0000 (17:26 +0000)
git-svn-id: https://svn.dealii.org/trunk@32289 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/hp/mapping_collection.h
deal.II/source/hp/mapping_collection.cc

index 512a6872b49d143bf7da262ff8e1bccd63ff88d6..117d76bee04106f777a41238fc7fd4d43d7aaa7d 100644 (file)
@@ -148,16 +148,15 @@ namespace hp
   {
   private:
     /**
-     * A static MappingQ1
-     * object. We can't use the one
-     * in ::StaticMappingQ1 since
-     * we can't make sure that the
-     * constructor for that object
-     * is run before the
-     * constructor for the present
-     * static object.
+     * A static MappingQ1 object. We can't use the one in ::StaticMappingQ1
+     * since we can't make sure that the constructor for that object is run
+     * before we want to use the object (when constructing mapping_collection
+     * below).  Therefore we create a helper function which returns a
+     * reference to a static object that will be constructed the first time
+     * this function is called.
      */
-    static MappingQ1<dim,spacedim> mapping_q1;
+      static
+      MappingQ1<dim,spacedim>& return_static_mapping_q1();
 
   public:
     /**
index 0d9fdcfa83a507aa92cce9b06545f7091aac435c..eb59d77463377e3bf3bbaaa84202a25e92d2ba0a 100644 (file)
@@ -82,16 +82,17 @@ namespace hp
 //---------------------------------------------------------------------------
 
 
-
   template<int dim, int spacedim>
-  MappingQ1<dim,spacedim>
-  StaticMappingQ1<dim,spacedim>::mapping_q1;
-
+  MappingQ1<dim,spacedim>& StaticMappingQ1<dim,spacedim>::return_static_mapping_q1()
+  {
+    static MappingQ1<dim,spacedim> mapping;
+    return mapping;
+  }
 
   template<int dim, int spacedim>
   MappingCollection<dim,spacedim>
   StaticMappingQ1<dim,spacedim>::mapping_collection
-    = MappingCollection<dim,spacedim>(mapping_q1);
+    = MappingCollection<dim,spacedim>(StaticMappingQ1<dim,spacedim>::return_static_mapping_q1());
 
 }
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.