polyscope icon indicating copy to clipboard operation
polyscope copied to clipboard

tidy up on shutdown to allow multiple `init`/`shutdown` cycles per process

Open gkoulin opened this issue 1 year ago • 2 comments

  • Hide window.
  • Clear contextStack.
  • Reset cached lazy properties. Had to convert from namespace to struct to allow default initialisation reset.
  • Set state::initialized = false.

gkoulin avatar Oct 01 '24 07:10 gkoulin

thanks for this, it would be great to cleanly shutdown & reinitialize (some sloppy engineering on my part that I have put off fixing for many years)

I'm afraid of some subtle bugs due to static variables. I have been gradually removing/consolidating static variables wherever possible, but there are still some hanging around. Also, openGL resource management & shutdown.

After enabling tests, it looks like there's a huge amount of memory being leaked. I think maybe the render::engine is not being freed, and is getting recreated each time? It will take some more debugging; I started looking at this but ran out of time for now.

nmwsharp avatar Oct 02 '24 03:10 nmwsharp

Thanks for the feedback. I can't believe ASAN only checks memory leaks on GCC. That's really strange.

Anyway, I've updated ownership of the engine. render::engine is now a std::unique_ptr<Engine>. All other references to the concrete engine, private to the backend, are essentially weak raw pointers.

gkoulin avatar Oct 02 '24 11:10 gkoulin

This looks to be superceeded by #311

gkoulin avatar Jan 28 '25 10:01 gkoulin