Opened 9 years ago

Closed 9 years ago

#491 closed defect (fixed)

Crash closing side view and opening shell

Reported by: tic20@… Owned by: Tom Goddard
Priority: major Milestone: Alpha Release
Component: Graphics Version:
Keywords: Cc:
Blocked By: Blocking:
Notify when closed: Platform: all
Project: ChimeraX

Description

Crash on Linux after showing side view, then closing side view, then opening shell.

On Mac this sequence does not crash but causes the main window to turn completely black as if the Qt opengl context is corrupted.

Begin forwarded message:

From: Tristan Croll
Subject: Segmentation fault
Date: November 30, 2016 at 6:23:15 AM PST
To: Tom Goddard, Greg Couch, Conrad Huang

Hi all,

Just noting a reproducible segfault I came across by accident (in the Linux build). If I start ChimeraX, open the side view tool, immediately close that and then attempt to open the shell, it crashes with the below dump.

Cheers,

Tristan

Fatal Python error: Segmentation fault

Thread 0x00007faeb0fe9700 (most recent call first):

File "/home/tic20/apps/chimerax/lib/python3.5/site-packages/zmq/utils/garbage.py", line 47 in run
File "/home/tic20/apps/chimerax/lib/python3.5/threading.py", line 914 in _bootstrap_inner
File "/home/tic20/apps/chimerax/lib/python3.5/threading.py", line 882 in _bootstrap

Thread 0x00007faea5b98700 (most recent call first):

File "/home/tic20/apps/chimerax/lib/python3.5/site-packages/zmq/sugar/poll.py", line 99 in poll
File "/home/tic20/apps/chimerax/lib/python3.5/site-packages/zmq/eventloop/ioloop.py", line 122 in poll
File "/home/tic20/apps/chimerax/lib/python3.5/site-packages/tornado/ioloop.py", line 862 in start
File "/home/tic20/apps/chimerax/lib/python3.5/site-packages/zmq/eventloop/ioloop.py", line 177 in start
File "/home/tic20/apps/chimerax/lib/python3.5/site-packages/ipykernel/iostream.py", line 72 in _thread_main
File "/home/tic20/apps/chimerax/lib/python3.5/threading.py", line 862 in run
File "/home/tic20/apps/chimerax/lib/python3.5/threading.py", line 914 in _bootstrap_inner
File "/home/tic20/apps/chimerax/lib/python3.5/threading.py", line 882 in _bootstrap

Current thread 0x00007faf9351f740 (most recent call first):

File "/home/tic20/apps/chimerax/lib/python3.5/site-packages/chimerax/core/ui/gui.py", line 166 in event_loop
File "/home/tic20/apps/chimerax/lib/python3.5/site-packages/ChimeraX_main.py", line 547 in init
File "/home/tic20/apps/chimerax/lib/python3.5/site-packages/ChimeraX_main.py", line 638 in <module>
File "/home/tic20/apps/chimerax/lib/python3.5/runpy.py", line 85 in _run_code
File "/home/tic20/apps/chimerax/lib/python3.5/runpy.py", line 170 in _run_module_as_main

/home/tic20/bin/ChimeraX: line 7: 12680 Segmentation fault (core dumped) $CHIMERA_HOME/bin/ChimeraX $*

Change History (14)

comment:1 by Tom Goddard, 9 years ago

Debugging on Mac shows that if a model is open (1a0m) when the side view is opened, then the bug does not occur. It only happens when no model is opened. If a model is opened, then closed, then side view is shown, closed, and shell opened then the main window still goes black.

Also if the side view exposeEvent() routine does not render, then everything works. exposeEvent() calls the side view render() routine directly. If instead it sets main_view.redraw_needed = True, the bug still occurs. So it seems that if the first rendering to the side view has no models then the bug occurs.

comment:2 by Tom Goddard, 9 years ago

If the side view render() routine does not call self.view.draw() then there is no problem. So it looks like calling the View.draw() routine when no models are shown maybe corrupts the Qt OpenGL context.

comment:3 by Tom Goddard, 9 years ago

If instead of having a molecule model open I have a map open (emdb 1080) then show side view, close side view, open shell causes the log window graphics to get messed up where only part of it seems to be redrawn (maybe the viewport is messed up).

comment:4 by Tom Goddard, 9 years ago

Why is closing the side view necessary to cause this problem? It doesn't happen if side view is left shown. Debugging shows that after closing side view it never tries to render, and setting all the side view canvas attributes to None assures the are not used after the close. Closing (with the panel close button in upper left corner) does not cause the side view to render one last time. So how is it that the close has an effect on later Qt display of the main window? The opengl context is not closed, it uses the same context as the main window. The side view View object destruction does no clean up.

Equally mystifying is why the shell has to be opened before the main window turns black. After closing the side view, maps and molecules can be open, the main window resized, all the panels dragged out, new tools can be started including toolshed that starts as a separate window, the main window functions completely normally with all of this, until the shell is shown. What is special about showing the shell? The line in the shell code that causes the black main window is "from qtconsole.rich_jupyter_widget import RichJupyterWidget". Even if this module is not used the main window goes black. It is enough to "import qtconsole.rich_jupyter_widget" and show the shell panel with no shell child widget. Apparently some side-effect of importing that module leads to the problem. If I put that import in the side view close() method then showing the shell does not cause any problem!

comment:5 by Tom Goddard, 9 years ago

I spent half a day investigating this obscure problem because the symptoms on Mac where the main window becomes entirely black (with some traces of junk textures) occurs in other circumstances when a long running command is executed. My hypothesis has been that the OpenGL contexts used by Qt for drawing widgets and ChimeraX for rendering graphics get mixed up with either Qt trying to draw widgets with the graphics window context or ChimeraX accidentally using the Qt context. I'm not sure this is the source of the problem. I cleaned up the side view sharing of the opengl context with the graphics window and did not see anything wrong with the code. I have changed the code so after Chimera draws graphics it immediately sets no current opengl context so Qt can't accidentally use our context. That didn't fix this problem.

More work could be done to figure out what code when importing qconsole.rich_jupyter_widget makes the main window go black. But that code imports a ton of other files so it is a real goose chase.

If I have the graphics draw routine return without doing anything then no bug is encountered. If I only comment out the side view draw call also no bug. Why opengl state set by a side view draw of no models would have no visible effect until the shell window is shown -- hard to imagine.

I'm giving up on this bug for now.

comment:6 by tic20@…, 9 years ago

Hi Tom,

Sounds from your other emails like this may be one to hand off to the Qt 
devs. But for what it's worth, I came across a situation that triggers 
what appears to be the same bug while a model is open. If you open a 
model and select part of it, then do the following:

def focus_on_selection(session, view, atoms):
     v = view
     pad = 5.0
     bounds = atoms.scene_bounds
     v.center_of_rotation = center = bounds.center()
     bounds.xyz_min = bounds.xyz_min - pad
     bounds.xyz_max = bounds.xyz_max + pad
     radius = bounds.radius() + pad
     v.view_all(bounds)
     cam = v.camera
     vd = cam.view_direction()
     cp = v.clip_planes
     cp.set_clip_position('near', center - radius*vd, cam)
     cp.set_clip_position('far', center + radius*vd, cam)
     session.selection.clear()
     atoms.selected=True



from chimerax.core.atomic import selected_atoms
sel = selected_atoms(session)
focus_on_selection(session, session.main_view, sel)

... then close the shell, open and close the side view, and attempt to 
re-open the shell, then ChimeraX crashes.

Cheers,

Tristan





On 2016-11-30 18:30, ChimeraX wrote:

comment:7 by goddard@…, 9 years ago

Hi Tristan,

  Unfortunately there is no chance the Qt developers will solve this without a simple test case — ie. not running ChimeraX.

  My suspicion is that the shell (rich_jupyter_widget.py) is doing something very weird when you import the module.  How this is related to the side view is mysterious.  The one unusual thing the side view does is it retargets the main window OpenGL context temporarily to the side view window, then retargets it back to the main window.  It does this to draw the side view.  Why that would have any impact on Qt and the shell is unclear.  It is even more mysterious why having a molecule open seems to avoid the bug, while having a map open limits the damage to the log window.  All of this suggests that some OpenGL state change is the culprit.  But Qt should only use the Qt opengl context, and ChimeraX only uses its own opengl context, so no state change made by ChimeraX should effect Qt.  I don’t think it is worth spending a day on this given other priorities.  The problem of the main window going entirely black sometimes happens without the shell.  I have no reproducible case of that, but if I find such a case, I think debugging it may lead to the solution of this bug too.

	Tom

comment:8 by tic20@…, 9 years ago

Hi Tom,

I think something you did while chasing this bug has broken the Side 
View tool. At the moment, when I open it the model is partially or 
entirely outside its window, and scales when I rescale in the main 
window. I'm also unable to grab and drag the clipping planes.

Cheers,

Tristan

On 2016-12-01 19:13, ChimeraX wrote:

comment:9 by goddard@…, 9 years ago

On Mac side view is working correctly.  But I just installed on Linux and see that it seems to think the side view window is the same size as the main graphics window when it draws the side view.  I did change the side view opengl a good bit.  Should be able to fix this today.

comment:10 by goddard@…, 9 years ago

Ok, fixed the side view on Linux.  If you want to patch your current ChimeraX add the self.make_current() call in core/graphics/opengl.py in the use_shared_context() routine as shown below.

	Tom


    def use_shared_context(self, window, width, height):
        '''
        Switch opengl context to use the specified target window.
        Multiple Render instances can share the same opengl context
        using this method.
        '''
        oc = self._opengl_context
        prev_win = oc.window
        oc.window = window
        self.make_current()
        self.set_viewport(0,0,width,height)
        return prev_win

comment:11 by Tom Ferrin, 9 years ago

Milestone: Alpha Release

comment:12 by Tom Goddard, 9 years ago

In the current Mac ChimeraX Jan 30 2017 build which uses Qt 5.7.1 (previous builds used Qt 5.7.0) opening and closing side view and then opening shell still causes the main window to go black. But only if the side view panel is tall enough so its graphics is drawn.

Opening 1a0m then opening and closing side view and the opening shell cause sthe log to be corrupted where only the right half of the log panel has text visible.

comment:13 by Tom Goddard, 9 years ago

In current Mac build Feb 23 2017 showing side view, making sure it draws (resize side view panel big enough if needed), close side view, then show shell causes a crash with traceback to shell:

$ cx
Fatal Python error: Segmentation fault

Thread 0x0000700005439000 (most recent call first):

File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/zmq/utils/garbage.py", line 47 in run
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 914 in _bootstrap_inner
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 882 in _bootstrap

Thread 0x0000700004f36000 (most recent call first):

File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/zmq/sugar/poll.py", line 99 in poll
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/zmq/eventloop/ioloop.py", line 122 in poll
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tornado/ioloop.py", line 862 in start
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/zmq/eventloop/ioloop.py", line 177 in start
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/ipykernel/iostream.py", line 72 in _thread_main
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 862 in run
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 914 in _bootstrap_inner
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 882 in _bootstrap

Thread 0x0000700004a33000 (most recent call first):

File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 293 in wait
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 549 in wait
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/IPython/core/history.py", line 834 in run
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/IPython/core/history.py", line 60 in needs_sqlite
File "<decorator-gen-23>", line 2 in run
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 914 in _bootstrap_inner
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 882 in _bootstrap

Current thread 0x00007fffaef3d3c0 (most recent call first):

File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/chimerax/core/ui/gui.py", line 171 in event_loop
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/ChimeraX_main.py", line 552 in init
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/ChimeraX_main.py", line 643 in <module>
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 85 in _run_code
File "/Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 170 in _run_module_as_main

Segmentation fault: 11

comment:14 by Tom Goddard, 9 years ago

Resolution: fixed
Status: newclosed

Fixed.

Side view Drawing for eye and field of view lines and clip planes did not have "delete()" called before Python released it. That caused the OpenGL resources to be deleted when the OpenGL context was not current (or possibly the Qt OpenGL context was current), and that caused the subsequent crash. Apparently glDelete...() calls with the wrong current context can lead to crashes.

Ticket #563 is the same crash on Windows.

Note: See TracTickets for help on using tickets.