order of d'tors for global variables: create VSSolution on demand, which is later

This commit is contained in:
Joachim Schöberl 2017-08-28 18:19:20 +02:00
parent e33c859a43
commit 7e83edabf1
5 changed files with 39 additions and 12 deletions

View File

@ -4,6 +4,15 @@
namespace netgen 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; // stringstream emptystr;
// ostream * testout = &emptystr; // ostream * testout = &emptystr;
// testout -> clear(ios::failbit); // testout -> clear(ios::failbit);
@ -17,8 +26,10 @@ namespace netgen
ostream * myerr = &cerr; 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> mesh; DLL_HEADER shared_ptr<Mesh> mesh;
DLL_HEADER shared_ptr<NetgenGeometry> ng_geometry; DLL_HEADER shared_ptr<NetgenGeometry> ng_geometry;
// TraceGlobal glob2("global2");
weak_ptr<Mesh> global_mesh; weak_ptr<Mesh> global_mesh;
void SetGlobalMesh (shared_ptr<Mesh> m) void SetGlobalMesh (shared_ptr<Mesh> m)

View File

@ -38,6 +38,7 @@ namespace netgen
int argc, tcl_const char *argv[]) int argc, tcl_const char *argv[])
{ {
auto & vssolution = netgen::GetVSSolution();
if (argc >= 2) if (argc >= 2)
{ {
if (strcmp (argv[1], "parameters") == 0) if (strcmp (argv[1], "parameters") == 0)
@ -306,6 +307,7 @@ namespace netgen
int i; int i;
char buf[1000]; char buf[1000];
buf[0] = 0; buf[0] = 0;
auto & vssolution = netgen::GetVSSolution();
if (argc >= 2) if (argc >= 2)
{ {

View File

@ -12,14 +12,22 @@
namespace netgen namespace netgen
{ {
VisualSceneSolution vssolution;
DLL_HEADER VisualSceneSolution & GetVSSolution()
{
static VisualSceneSolution vssolution;
return vssolution;
}
// extern shared_ptr<Mesh> mesh; // extern shared_ptr<Mesh> mesh;
extern VisualSceneMesh vsmesh; extern VisualSceneMesh vsmesh;
void AddUserVisualizationObject (UserVisualizationObject * vis) void AddUserVisualizationObject (UserVisualizationObject * vis)
{ {
vssolution.AddUserVisualizationObject (vis); // vssolution.AddUserVisualizationObject (vis);
GetVSSolution().AddUserVisualizationObject (vis);
} }
@ -38,6 +46,7 @@ namespace netgen
VisualSceneSolution :: VisualSceneSolution () VisualSceneSolution :: VisualSceneSolution ()
: VisualScene() : VisualScene()
{ {
// cout << "init VisualSceneSolution" << endl;
surfellist = 0; surfellist = 0;
linelist = 0; linelist = 0;
element1dlist = 0; element1dlist = 0;
@ -68,6 +77,7 @@ namespace netgen
VisualSceneSolution :: ~VisualSceneSolution () VisualSceneSolution :: ~VisualSceneSolution ()
{ {
// cout << "exit VisualSceneSolution" << endl;
ClearSolutionData(); ClearSolutionData();
} }
@ -416,7 +426,7 @@ namespace netgen
else else
{ {
glTranslatef (0.5, 0, 0); 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) if (fabs (maxval) > 1e-10)
glScalef(0.5/maxval, 0.5/maxval, 0.5/maxval); glScalef(0.5/maxval, 0.5/maxval, 0.5/maxval);
else else
@ -4773,7 +4783,8 @@ void Ng_ClearSolutionData ()
{ {
#ifdef OPENGL #ifdef OPENGL
// if (nodisplay) return; // if (nodisplay) return;
netgen::vssolution.ClearSolutionData(); // netgen::vssolution.ClearSolutionData();
netgen::GetVSSolution().ClearSolutionData();
#endif #endif
} }
@ -4810,7 +4821,8 @@ void Ng_SetSolutionData (Ng_SolutionData * soldata)
vss->draw_volume = soldata->draw_volume; vss->draw_volume = soldata->draw_volume;
vss->soltype = netgen::VisualSceneSolution::SolType (soldata->soltype); vss->soltype = netgen::VisualSceneSolution::SolType (soldata->soltype);
vss->solclass = soldata->solclass; vss->solclass = soldata->solclass;
netgen::vssolution.AddSolutionData (vss); // netgen::vssolution.AddSolutionData (vss);
netgen::GetVSSolution().AddSolutionData (vss);
#endif #endif
} }
@ -4824,7 +4836,8 @@ namespace netgen
void Ng_Redraw (bool blocking) void Ng_Redraw (bool blocking)
{ {
#ifdef OPENGL #ifdef OPENGL
netgen::vssolution.UpdateSolutionTimeStamp(); //netgen::vssolution.UpdateSolutionTimeStamp();
netgen::GetVSSolution().UpdateSolutionTimeStamp();
netgen::Render(blocking); netgen::Render(blocking);
#endif #endif
} }

View File

@ -447,7 +447,8 @@ public:
DLL_HEADER extern VisualSceneSolution vssolution; // DLL_HEADER extern VisualSceneSolution vssolution;
DLL_HEADER extern VisualSceneSolution & GetVSSolution();
} }

View File

@ -470,7 +470,7 @@ namespace netgen
const char * filename = argv[1]; const char * filename = argv[1];
PrintMessage (1, "Save solution to file ", filename); PrintMessage (1, "Save solution to file ", filename);
vssolution.SaveSolutionData (filename); netgen::GetVSSolution().SaveSolutionData (filename);
return TCL_OK; return TCL_OK;
} }
@ -1890,7 +1890,7 @@ namespace netgen
// if (strcmp (vismode, "surfmeshing") == 0) vs = &vssurfacemeshing; // if (strcmp (vismode, "surfmeshing") == 0) vs = &vssurfacemeshing;
if (strcmp (vismode, "specpoints") == 0) vs = &vsspecpoints; 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) 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, Tcl_Interp * interp,
int argc, tcl_const char *argv[]) int argc, tcl_const char *argv[])
{ {
vssolution.BuildFieldLinesPlot(); netgen::GetVSSolution().BuildFieldLinesPlot();
return TCL_OK; return TCL_OK;
} }