[pydocview] Segmentation fault when opening two SDI views with the same document

Hi!

In my application I'd like to be be able to open two or more
views with one document. I had some problems with this, so I
tried to change the pydocview demo in the samples folder to
open two views instead of one by changing these lines in
TextEditorApplication.OnInit():

if not docManager.GetDocuments() and docManager.GetFlags() & wx.lib.docview.DOC_SDI:
    textTemplate.CreateDocument('', docview.DOC_NEW).OnNewDocument()

to:

if not docManager.GetDocuments() and docManager.GetFlags() & wx.lib.docview.DOC_SDI:
    doc = textTemplate.CreateDocument('', wx.lib.docview.DOC_NEW)
    doc.OnNewDocument()
    textTemplate.CreateView(doc, 0)

I now get two windows, but when I close both of them (not with File/Exit, but using
the window's Close button, the one that's top right in Windows) I get a segmentation
fault. Is this the wrong way to open multiple views for a single document?

I am using wxpython 2.6.3.3 on Gentoo Linux.

Regards,

Klaus

Klaus Nowikow wrote:

In my application I'd like to be be able to open two or more
views with one document. I had some problems with this, so I

Sorry, I just noticed that I forgot to mention that I want to use the SDI
interface.

tried to change the pydocview demo in the samples folder to
open two views instead of one by changing these lines in
TextEditorApplication.OnInit():

if not docManager.GetDocuments() and docManager.GetFlags() & wx.lib.docview.DOC_SDI:
    textTemplate.CreateDocument('', docview.DOC_NEW).OnNewDocument()

to:

if not docManager.GetDocuments() and docManager.GetFlags() & wx.lib.docview.DOC_SDI:
    doc = textTemplate.CreateDocument('', wx.lib.docview.DOC_NEW)
    doc.OnNewDocument()
    textTemplate.CreateView(doc, 0)

I now get two windows, but when I close both of them (not with File/Exit, but using
the window's Close button, the one that's top right in Windows) I get a segmentation
fault. Is this the wrong way to open multiple views for a single document?

In my own application I get a traceback when I close one of the
windows and move the mouse over the other (see bottom of the message).

Could this be because the document references a CommandProcessor object,
which in turn references only one Edit menu (see the CommandProcessor.GetEditMenu()
method)? When closing the window, the respective menu will be deleted and the
CommandProcessor references a dead object.

Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/wx-2.6-gtk2-unicode/wx/lib/pydocview.py", line 2435, in
ProcessUpdateUIEvent
    if docMgr.ProcessUpdateUIEvent(event): # Let the views handle the event before the services
  File "/usr/lib/python2.5/site-packages/wx-2.6-gtk2-unicode/wx/lib/docview.py", line 1803, in
ProcessUpdateUIEvent
    self.OnUpdateRedo(event)
  File "/usr/lib/python2.5/site-packages/wx-2.6-gtk2-unicode/wx/lib/docview.py", line 1665, in
OnUpdateRedo
    doc.GetCommandProcessor().SetMenuStrings()
  File "/usr/lib/python2.5/site-packages/wx-2.6-gtk2-unicode/wx/lib/docview.py", line 3150, in
SetMenuStrings
    undoItem = self.GetEditMenu().FindItemById(wx.ID_UNDO)
  File "/usr/lib/python2.5/site-packages/wx-2.6-gtk2-unicode/wx/_core.py", line 13481, in __getattr__
    raise PyDeadObjectError(self.attrStr % self._name)
wx._core.PyDeadObjectError: The C++ part of the Menu object has been deleted, attribute access no
longer allowed.

Klaus Nowikow wrote:

Klaus Nowikow wrote:

In my application I'd like to be be able to open two or more
views with one document. I had some problems with this, so I

Sorry, I just noticed that I forgot to mention that I want to use the SDI
interface.

tried to change the pydocview demo in the samples folder to
open two views instead of one by changing these lines in
TextEditorApplication.OnInit():

if not docManager.GetDocuments() and docManager.GetFlags() & wx.lib.docview.DOC_SDI:
    textTemplate.CreateDocument('', docview.DOC_NEW).OnNewDocument()

to:

if not docManager.GetDocuments() and docManager.GetFlags() & wx.lib.docview.DOC_SDI:
    doc = textTemplate.CreateDocument('', wx.lib.docview.DOC_NEW)
    doc.OnNewDocument()
    textTemplate.CreateView(doc, 0)

I now get two windows, but when I close both of them (not with File/Exit, but using
the window's Close button, the one that's top right in Windows) I get a segmentation
fault. Is this the wrong way to open multiple views for a single document?

I can't duplicate this with 2.8.6.0 but does it make a difference if you use docManager.CreateView instead? It looks like that is what is intended to be used to add a new view for an existing document.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Klaus Nowikow wrote:

Klaus Nowikow wrote:

In my application I'd like to be be able to open two or more
views with one document. I had some problems with this, so I
[...]

I now get two windows, but when I close both of them (not with File/Exit, but using
the window's Close button, the one that's top right in Windows) I get a segmentation
fault. Is this the wrong way to open multiple views for a single document?

I can't duplicate this with 2.8.6.0 but does it make a difference if you use docManager.CreateView instead? It looks like that is what is intended to be used to add a new view for an existing document.

Hm, I just tried it with 2.8 on Windows and it works, both in my
application and in the pyDocViewDemo.
So, I think I'll try installing wx 2.8 on my Linux box.
Unfortunately, there's still only 2.6 in the Gentoo repository,
so I'll have to install it by hand :-(. Or I'll go looking for
an overlay that contains 2.8.

Haven't tried the docManager.CreateView() path yet because I am
not in the office today, but judging from the source code of
that method I don't think that this would change anything, as
it just searches for a doc template, calls CreateView() on it
and sets the name of the window.

But anyway, thank you for trying to reproduce that problem and
pointing me in this direction.

···

--
Klaus