ortk95 / planetmapper

PlanetMapper: An open source Python package for visualising, navigating and mapping Solar System observations
https://planetmapper.readthedocs.io
MIT License
11 stars 1 forks source link

Segmentation fault when running GUI #258

Closed ortk95 closed 1 year ago

ortk95 commented 1 year ago

From Mike:

when I run planetmapper on my mac, it makes the map, then crashes once it is complete and says: Segmentation fault: 11, “python quit unexpectedly”

Can't reproduce on my mac/linux systems, so potentially a bug related to a specific version/processor etc.

ortk95 commented 1 year ago

Issue occurs for Mike with Ventura 13.3.1, Python 3.10.8, M2 processor Doesn't occur for me with Ventura 13.4, Python 3.10 (or 3.11), Intel processor

So seems like it's maybe an M2 specific issue

ortk95 commented 1 year ago

Mike's output of running debug_crash.py with PlanetMapper 1.7.6

...

Saving file...
2023-07-10 13:36:10.241420 ------> check_path utils.py:269
2023-07-10 13:36:10.241964 <------- check_path utils.py:282
File saved
2023-07-10 13:36:10.919462 <------ save_mapped_observation observation.py:1030
2023-07-10 13:36:10.932284 -----> _update_progress_hook base.py:547
2023-07-10 13:36:10.932316 ------> __call__ progress.py:122
2023-07-10 13:36:10.932337 -------> update_bar gui.py:2272
2023-07-10 13:36:10.946453 <-------- update_bar gui.py:2279
2023-07-10 13:36:10.946482 <------- __call__ progress.py:141
2023-07-10 13:36:10.946490 <------ _update_progress_hook base.py:550
2023-07-10 13:36:10.946503 <----- decorated progress.py:36
2023-07-10 13:36:10.946518 ----> _remove_progress_hook base.py:543
2023-07-10 13:36:10.946529 <----- _remove_progress_hook base.py:545
2023-07-10 13:36:10.950169 <---- run_save gui.py:2244
2023-07-10 13:36:10.950203 ---> get_observation gui.py:368
2023-07-10 13:36:10.950218 <---- get_observation gui.py:372
2023-07-10 13:36:10.950224 ---> _remove_progress_hook base.py:543
2023-07-10 13:36:10.950230 <---- _remove_progress_hook base.py:545
2023-07-10 13:36:10.950246 ---> set_help_hint gui.py:730
2023-07-10 13:36:10.950337 <---- set_help_hint gui.py:731
2023-07-10 13:36:10.950344 <--- try_run_save gui.py:2144
2023-07-10 13:36:10.950351 <-- click_save gui.py:2053
Segmentation fault: 11

so seems like crash is happening when control is handed back to tk mainloop

ortk95 commented 1 year ago

I can reproduce by running in VS Code integrated terminal. debug_crash.py output (with 'planetmapper' not in filename guard commented out; v1.7.5):

...

2023-07-10 14:22:42.672263 ------> SpiceBase._remove_progress_hook base.py:543
2023-07-10 14:22:42.672285 <------- SpiceBase._remove_progress_hook base.py:545
2023-07-10 14:22:42.672309 ------> Pack.pack_configure __init__.py:2436
2023-07-10 14:22:42.672332 -------> Misc._options __init__.py:1524
2023-07-10 14:22:42.672351 --------> _cnfmerge __init__.py:102
2023-07-10 14:22:42.672375 <--------- _cnfmerge __init__.py:105
2023-07-10 14:22:42.672400 <-------- Misc._options __init__.py:1548
2023-07-10 14:22:42.672441 <------- Pack.pack_configure __init__.py:2452
2023-07-10 14:22:42.672463 ------> Wm.wm_title __init__.py:2280
2023-07-10 14:22:42.673449 <------- Wm.wm_title __init__.py:2282
2023-07-10 14:22:42.673488 <------ SavingProgress.run_save gui.py:2236
2023-07-10 14:22:42.673508 -----> GUI.get_observation gui.py:360
2023-07-10 14:22:42.673528 <------ GUI.get_observation gui.py:364
2023-07-10 14:22:42.673547 -----> SpiceBase._remove_progress_hook base.py:543
2023-07-10 14:22:42.673564 <------ SpiceBase._remove_progress_hook base.py:545
2023-07-10 14:22:42.673595 -----> GUI.set_help_hint gui.py:722
2023-07-10 14:22:42.673620 ------> Misc.configure __init__.py:1695
2023-07-10 14:22:42.673639 -------> Misc._configure __init__.py:1682
2023-07-10 14:22:42.673658 --------> _cnfmerge __init__.py:102
2023-07-10 14:22:42.673701 <--------- _cnfmerge __init__.py:117
2023-07-10 14:22:42.673735 --------> Misc._options __init__.py:1524
2023-07-10 14:22:42.673753 ---------> _cnfmerge __init__.py:102
2023-07-10 14:22:42.673775 <---------- _cnfmerge __init__.py:105
2023-07-10 14:22:42.673823 <--------- Misc._options __init__.py:1548
2023-07-10 14:22:42.674261 <-------- Misc._configure __init__.py:1692
2023-07-10 14:22:42.674285 <------- Misc.configure __init__.py:1702
2023-07-10 14:22:42.674298 <------ GUI.set_help_hint gui.py:723
2023-07-10 14:22:42.674309 <----- SaveObservation.try_run_save gui.py:2136
2023-07-10 14:22:42.674321 <---- SaveObservation.click_save gui.py:2045
2023-07-10 14:22:42.674337 <--- CallWrapper.__call__ __init__.py:1948
Segmentation fault: 11
ortk95 commented 1 year ago

With faulthandler.enable():

Fatal Python error: Segmentation fault

Current thread 0x00007ff8534ef640 (most recent call first):
  File "/Users/ortk1/opt/anaconda3/envs/py311/lib/python3.11/tkinter/__init__.py", line 1485 in mainloop
  File "/Users/ortk1/Dropbox/science/planetmapper/planetmapper/gui.py", line 303 in run
  File "/Users/ortk1/Dropbox/science/planetmapper/planetmapper/observation.py", line 1195 in run_gui
  File "/Users/ortk1/Dropbox/science/planetmapper/scratchpad_gui.py", line 17 in <module>
ortk95 commented 1 year ago

In my VS code integrated terminal, v1.6.5 runs fine, v1.7.0 crashes

https://github.com/ortk95/planetmapper/compare/v1.6.5...v1.7.0

ortk95 commented 1 year ago

Seems like bug was introduced in be67f86836a1ffeb3ff4507af7c95b07bdcae6f7

ortk95 commented 1 year ago

Doesn't crash with include_wireframe=False when saving observation

ortk95 commented 1 year ago

Seems like issue is caused by calling plt.close(fig) while another figure is embdedded in tkinter. Fixable by using Figure() rather than plt.figure() to create figures.

https://stackoverflow.com/questions/69515455/how-to-properly-close-tkinter-toplevel-with-matplotlib-embeded https://matplotlib.org/stable/gallery/user_interfaces/embedding_in_tk_sgskip.html