MathInspector / MathInspector

A visual programing environment for scientific computing with python
GNU General Public License v3.0
894 stars 64 forks source link

Error when trying to toggle plot grid #41

Open EtienneDesticourt opened 3 years ago

EtienneDesticourt commented 3 years ago

Hi,

I get the following error when trying to toggle the grid in plots. I'm on linux running the PR 38 dev branch:

Exception in Tkinter callback
Traceback (most recent call last):

  File "/usr/lib/python3.8/tkinter/__init__.py", line 1883, in __call__
    return self.func(*args)

  File "/***/MathInspector/mathinspector/mainmenu.py", line 354, in plotconfig
    plot.config(**{ key : not opts[key] })

  File "/***/MathInspector/mathinspector/plot/__init__.py", line 137, in config
    self.active_window.config(**kwargs)

  File "/***/MathInspector/mathinspector/plot/plot3d.py", line 334, in config
    pygame.event.post(pygame.event.Event(pygame.USEREVENT, kwargs=kwargs))

pygame.error: video system not initialized

Cheers

MathInspector commented 3 years ago

The menu is totally f**cked on linux. I have a plan to completely rewrite the entire menu thing and hold tkinter menu's hand very very carefully until I figure out why the menu is like this.

MathInspector commented 3 years ago

I have known about the grid toggle issue forever but the error message you showed me is new. This might be a new lead! I'm kind of sick of tkinter menu doing this and it's my own fault for trying to run

app.update()

from a pygame instance when I know under the hood there is a secret race condition in tkinter menu I haven't been able to contain at all. Updating to Nightmare level. You discovered the ultimate bug lmao I had been keeping this one top secret =)

EtienneDesticourt commented 3 years ago

Hmm don't know about those Tkinter issues but as far as this error goes it should be solvable by calling pygame.init() right after it's imported in your main script. If you call it only when you plot you'll have systems which are not initialized and so, for example, when a user event is fired you'll get this error.

MathInspector commented 3 years ago

I found a reproducible bug where I can crash the app every time, here are the steps

I don't actually understand what the problem is. But my guess is that pygame and tkinter are fighting with each other for control of the main python interpreter loop and in a C++ call under the hood there is a bug where memory was allocated and then not properly deallocated as pygame and tkinter fight for control of the underlying process.

I have investigated this pretty deeply and it seems what is going on is the tkinter menu system works completely differently to almost everything else in tkinter. tcl gets compiled and then python hooks into the tcl binary, and the menu system is using like 10 api's which are not being exposed in the python tkinter interface.

My hope is that I made some kind of mistake when I wrote the wrapper class for menu and it will all go away if I rewrite everything from scratch.