Hi all,
My sample application crashes with “Heap corruption” error on a few windows machines. The same app works fine on a different Windows 10 version with the same Python and wxpython package. On debugging I figured out, my logger (Python’s logging library) is getting corrupted somehow on the machines where this is seen.
OS - Windows 10 French (1809 - build: 17763) - works on other windows versions
wxPython - 4.1.1 (pypi), Python 3.9.7 (stock)
Need some directions on further debugging this issue.
import wx
import wx.adv
import logging
import sys
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
TRAY_ICON = "path to some icon" # replace with path to a icon file. Not necessary to get the code working
def create_menu_item(menu, label, func):
item = wx.MenuItem(menu, -1, label)
menu.Bind(wx.EVT_MENU, func, id=item.GetId())
menu.Append(item)
return item
class SampleApp(wx.adv.TaskBarIcon):
def __init__(self):
wx.adv.TaskBarIcon.__init__(self)
self.set_icon(TRAY_ICON)
self.Bind(wx.adv.EVT_TASKBAR_RIGHT_DOWN, self.on_right_down)
def CreatePopupMenu(self):
menu = wx.Menu()
create_menu_item(menu, 'Say Hello', self.on_hello)
menu.AppendSeparator()
create_menu_item(menu, 'Exit', self.on_exit)
return menu
def set_icon(self, path):
icon = wx.Icon(wx.Bitmap(path))
self.SetIcon(icon, 'hello world!!!')
def on_right_down(self, event):
pass
def on_hello(self, event):
print ('Hello, world!')
def on_exit(self, event):
wx.CallAfter(self.Destroy)
if __name__ == '__main__':
logger.info('Starting App') # log 1
app = wx.App()
logger.info('App obj created') # log 2
SampleApp()
app.MainLoop()
logger.info('App closed') # log 3
The loggers fail with heap corruption after calling wx.App(). As App is not yet started, log 2 still gets called from the python’s main thread. Not sure how this gets corrupted in few machines, and works just fine else where.
Commenting out log 2,3 will get the app working on those windows were it is failing.