From 7e83edabf1d520755db002c6a73a6b35facc88d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Mon, 28 Aug 2017 18:19:20 +0200 Subject: [PATCH] order of d'tors for global variables: create VSSolution on demand, which is later --- libsrc/meshing/global.cpp | 13 ++++++++++++- libsrc/visualization/visualpkg.cpp | 2 ++ libsrc/visualization/vssolution.cpp | 25 +++++++++++++++++++------ libsrc/visualization/vssolution.hpp | 3 ++- ng/ngpkg.cpp | 8 ++++---- 5 files changed, 39 insertions(+), 12 deletions(-) diff --git a/libsrc/meshing/global.cpp b/libsrc/meshing/global.cpp index dd3e14bd..df6bcece 100644 --- a/libsrc/meshing/global.cpp +++ b/libsrc/meshing/global.cpp @@ -4,6 +4,15 @@ namespace netgen { + + class TraceGlobal + { + string name; + public: + TraceGlobal(string _name) : name(_name) { cout << "init global " << name << endl; } + ~TraceGlobal() { cout << "exit global " << name << endl; } + }; + // stringstream emptystr; // ostream * testout = &emptystr; // testout -> clear(ios::failbit); @@ -16,9 +25,11 @@ namespace netgen ostream * mycout = &cout; ostream * myerr = &cerr; - // some functions (visualization) still need a global mesh + // some functions (visualization) still need a global mesh + // TraceGlobal glob1("global1"); DLL_HEADER shared_ptr mesh; DLL_HEADER shared_ptr ng_geometry; + // TraceGlobal glob2("global2"); weak_ptr global_mesh; void SetGlobalMesh (shared_ptr m) diff --git a/libsrc/visualization/visualpkg.cpp b/libsrc/visualization/visualpkg.cpp index 79ba3067..c660f77f 100644 --- a/libsrc/visualization/visualpkg.cpp +++ b/libsrc/visualization/visualpkg.cpp @@ -38,6 +38,7 @@ namespace netgen int argc, tcl_const char *argv[]) { + auto & vssolution = netgen::GetVSSolution(); if (argc >= 2) { if (strcmp (argv[1], "parameters") == 0) @@ -306,6 +307,7 @@ namespace netgen int i; char buf[1000]; buf[0] = 0; + auto & vssolution = netgen::GetVSSolution(); if (argc >= 2) { diff --git a/libsrc/visualization/vssolution.cpp b/libsrc/visualization/vssolution.cpp index c5bb4642..f82a1ffe 100644 --- a/libsrc/visualization/vssolution.cpp +++ b/libsrc/visualization/vssolution.cpp @@ -12,14 +12,22 @@ namespace netgen { - VisualSceneSolution vssolution; + + DLL_HEADER VisualSceneSolution & GetVSSolution() + { + static VisualSceneSolution vssolution; + return vssolution; + } + + // extern shared_ptr mesh; extern VisualSceneMesh vsmesh; void AddUserVisualizationObject (UserVisualizationObject * vis) { - vssolution.AddUserVisualizationObject (vis); + // vssolution.AddUserVisualizationObject (vis); + GetVSSolution().AddUserVisualizationObject (vis); } @@ -38,6 +46,7 @@ namespace netgen VisualSceneSolution :: VisualSceneSolution () : VisualScene() { + // cout << "init VisualSceneSolution" << endl; surfellist = 0; linelist = 0; element1dlist = 0; @@ -68,6 +77,7 @@ namespace netgen VisualSceneSolution :: ~VisualSceneSolution () { + // cout << "exit VisualSceneSolution" << endl; ClearSolutionData(); } @@ -416,7 +426,7 @@ namespace netgen else { glTranslatef (0.5, 0, 0); - glRotatef(360 * vssolution.time, 0, 0, -1); + glRotatef(360 * netgen::GetVSSolution().time, 0, 0, -1); if (fabs (maxval) > 1e-10) glScalef(0.5/maxval, 0.5/maxval, 0.5/maxval); else @@ -4773,7 +4783,8 @@ void Ng_ClearSolutionData () { #ifdef OPENGL // if (nodisplay) return; - netgen::vssolution.ClearSolutionData(); + // netgen::vssolution.ClearSolutionData(); + netgen::GetVSSolution().ClearSolutionData(); #endif } @@ -4810,7 +4821,8 @@ void Ng_SetSolutionData (Ng_SolutionData * soldata) vss->draw_volume = soldata->draw_volume; vss->soltype = netgen::VisualSceneSolution::SolType (soldata->soltype); vss->solclass = soldata->solclass; - netgen::vssolution.AddSolutionData (vss); + // netgen::vssolution.AddSolutionData (vss); + netgen::GetVSSolution().AddSolutionData (vss); #endif } @@ -4824,7 +4836,8 @@ namespace netgen void Ng_Redraw (bool blocking) { #ifdef OPENGL - netgen::vssolution.UpdateSolutionTimeStamp(); + //netgen::vssolution.UpdateSolutionTimeStamp(); + netgen::GetVSSolution().UpdateSolutionTimeStamp(); netgen::Render(blocking); #endif } diff --git a/libsrc/visualization/vssolution.hpp b/libsrc/visualization/vssolution.hpp index dbf61150..56d757df 100644 --- a/libsrc/visualization/vssolution.hpp +++ b/libsrc/visualization/vssolution.hpp @@ -447,7 +447,8 @@ public: -DLL_HEADER extern VisualSceneSolution vssolution; + // DLL_HEADER extern VisualSceneSolution vssolution; +DLL_HEADER extern VisualSceneSolution & GetVSSolution(); } diff --git a/ng/ngpkg.cpp b/ng/ngpkg.cpp index 5d29d8f3..ee9e0b20 100644 --- a/ng/ngpkg.cpp +++ b/ng/ngpkg.cpp @@ -470,7 +470,7 @@ namespace netgen const char * filename = argv[1]; PrintMessage (1, "Save solution to file ", filename); - vssolution.SaveSolutionData (filename); + netgen::GetVSSolution().SaveSolutionData (filename); return TCL_OK; } @@ -1890,7 +1890,7 @@ namespace netgen // if (strcmp (vismode, "surfmeshing") == 0) vs = &vssurfacemeshing; if (strcmp (vismode, "specpoints") == 0) vs = &vsspecpoints; - if (strcmp (vismode, "solution") == 0) vs = &vssolution; + if (strcmp (vismode, "solution") == 0) vs = &netgen::GetVSSolution(); } } @@ -2414,7 +2414,7 @@ void Ng_SetMouseEventHandler (netgen::MouseEventHandler * handler) void Ng_SetUserVisualizationObject (netgen::UserVisualizationObject * vis) { - vssolution.AddUserVisualizationObject (vis); + netgen::GetVSSolution().AddUserVisualizationObject (vis); } @@ -2651,7 +2651,7 @@ void PlayAnimFile(const char* name, int speed, int maxcnt) Tcl_Interp * interp, int argc, tcl_const char *argv[]) { - vssolution.BuildFieldLinesPlot(); + netgen::GetVSSolution().BuildFieldLinesPlot(); return TCL_OK; }