LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Blogs > dr_agon
User Name
Password

Notices

Rate this Entry

Avoiding wxPython PrintPreview segmentation fault or double free error

Posted 11-28-2008 at 08:23 PM by dr_agon

applies to: Python, wxPython (v.2.8), wxWidgets, wx.PrintPreview, wx.Printout

When creating wx.PrintPreview class, you must pass 2 parameters of wxPrintout class (see doc)
If someone (like me) gets a silly idea of passing the same instance of wxPrintout class as both parameters, on closing the preview frame he will get segmentation fault or double free error.
Example (don't do this!):
Code:
class MyPrintout(wx.Printout):
  
  #rest of code
  
printout = MyPrintout(MyParameters) #  instance of class based on wx.Printout 
printpreview = wx.PrintPreview(printout, printout, MyPrintData)
Even if both parameters must refer to the same class, they should be passed as different instances, like this:
Code:
class MyPrintout(wx.Printout):
  
  #rest of code
  
printout_preview = MyPrintout(MyParameters) # first instance of class based on wx.Printout 
printout_printing = MyPrintout(MyParameters) # second instance of class based on wx.Printout 
printpreview = wx.PrintPreview(printout_preview, printout_printing, MyPrintData)
Now, it seems logical to me, but cost me lots of time to figure it out.
Posted in Uncategorized
Views 1886 Comments 0
« Prev     Main     Next »

  



All times are GMT -5. The time now is 04:48 AM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration