Getting wx._core.wxAssertionError

140 views
Skip to first unread message

Ishan Buxy ce17b117

unread,
Dec 10, 2021, 12:15:15 PM12/10/21
to wxPython-users
Hi,

I'm using GRASS GIS 7.8, an application created using wxPython.

Every time I try to open a dataset using this application, I get the following error:
C:\Users\Ishan Buxy>Traceback (most recent call last):
  File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\wxgui.py", line 105, in OnInit
    mainframe = GMFrame(parent=None, id=wx.ID_ANY,
  File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\lmgr\frame.py", line 141, in __init__
    self._createMenuBar()
  File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\lmgr\frame.py", line 268, in _createMenuBar
    self.menubar = GMenu(
  File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\gui_core\menu.py", line 47, in __init__
    self.Append(self._createMenu(child), child.label)
  File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\gui_core\menu.py", line 61, in _createMenu
    self._createMenuItem(menu, label=child.label, **data)
  File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\gui_core\menu.py", line 88, in _createMenuItem
    menuItem.SetBitmap(MetaIcon(img=icon).GetBitmap(self.bmpsize))
  File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\icons\icon.py", line 96, in GetBitmap
    image = wx.Image(name=self.imagepath)
wx._core.wxAssertionError: C++ assertion "strcmp(setlocale(0, 0), "C") == 0" failed at D:\src\osgeo4w\src\wxwidgets\wxwidgets-3.1.5-0df1d81acd6f1be8624022f8eecb51679008ca40\src\common\intl.cpp(1694) in wxLocale::GetInfo(): You probably called setlocale() directly instead of using wxLocale and now there is a mismatch between C/C++ and Windows locale.
Things are going to break, please only change locale by creating wxLocale objects to avoid this!
OnInit returned false, exiting...


Can someone please explain? How do I resolve this?

Regards,
Ishan

Tim Roberts

unread,
Dec 10, 2021, 2:17:08 PM12/10/21
to wxpytho...@googlegroups.com
Ishan Buxy ce17b117 wrote:

I'm using GRASS GIS 7.8, an application created using wxPython.

Every time I try to open a dataset using this application, I get the following error:
...
  File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\icons\icon.py", line 96, in GetBitmap
    image = wx.Image(name=self.imagepath)
wx._core.wxAssertionError: C++ assertion "strcmp(setlocale(0, 0), "C") == 0" failed at D:\src\osgeo4w\src\wxwidgets\wxwidgets-3.1.5-0df1d81acd6f1be8624022f8eecb51679008ca40\src\common\intl.cpp(1694) in wxLocale::GetInfo(): You probably called setlocale() directly instead of using wxLocale and now there is a mismatch between C/C++ and Windows locale.
Things are going to break, please only change locale by creating wxLocale objects to avoid this!
OnInit returned false, exiting...

You will need to contact the GRASS GIS people about this.  They have a Python installation embedded in their release.  All the pieces should be playing well together.  Perhaps you're using a code page they haven't encountered before.  They have their own mailing lists, and a Twitter feed.  This shouldn't be a hard fix (just one line), but I don't want to advise you without getting a comment from the authors.

https://grass.osgeo.org/about/community/

-- 
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Ishan Buxy (IIT Madras - CE17B117)

unread,
Dec 10, 2021, 2:47:21 PM12/10/21
to wxpytho...@googlegroups.com
Hi Tim

Thanks for the revert. I'll reach out to them.

Regards
Ishan

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/180959e2-05d1-9091-01e9-5eff9280da08%40probo.com.

Peter Clarke

unread,
Dec 11, 2021, 6:20:50 PM12/11/21
to wxPython-users
I've seen a similar issue recently in my own code. When I started using wx.Locale, an unrelated part of the code started throwing this error. The specific line throwing the error creates the first instance of wx.Image. The only way I've found to resolve it so far is either (1) get rid of wx.Locale usage completely, or (2) get rid of wx.Image usage. Not a pleasant choice.

I found the error was coming up on specific Windows machines only. I have not seen it on my own Windows or Mac. It first showed up on my colleague's Windows PC - she's Indian. As the OP has a .in email address, I wonder if it's a particular issue for Indian locale? Maybe (just a guess) because India is one of the few locales with a non-integer time difference from UCT?

Peter Clarke

Matt Newville

unread,
Dec 12, 2021, 10:35:24 AM12/12/21
to wxpytho...@googlegroups.com
I have had many reports of problems with locale, and only on Windows, and only with recent versions of wxPython (I think only 4.1.1, but I'm not certain of that). 

My solution was to subclass `wxApp` for any application that I distribute:

###
import wx
import locale
import platform

class MyWxApp(wx.App):
    """wrapper for wx apps, with the following arguments and features:
    Arguments
    ----------
      with_c_locale bool  whether to force C locale [None : see note 1]

    Notes
    ------
      By defaut (and if left ast `None`), then `with_c_locale`
      will be True for Windows, False for other systems

    """
    def __init__(self, with_c_locale=None, **kws):
        if with_c_locale is None:
            with_c_locale = (platform.system() == 'Windows')
        self.with_c_locale = with_c_locale
        wx.App.__init__(self, **kws)

    def InitLocale(self):
        """over-ride wxPython default initial locale"""
        if self.with_c_locale:
            self._initial_locale = None
            locale.setlocale(locale.LC_ALL, 'C')
        else:
            lang, enc = locale.getdefaultlocale()
            self._initial_locale = wx.Locale(lang, lang[:2], lang)
            locale.setlocale(locale.LC_ALL, lang)

    def OnInit(self):
        self.createApp()
        return True

    def createApp(self):
        return True

    def run(self):
        self.MainLoop()
###




--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages