SystemError: <class 'wx._glcanvas.GLAttributes'> returned a result with an exception set

I’m attempting to create a Flatpak from the Python-based Amulet Minecraft Map Editor. The Flatpak building is fine, and the app launches without an issue, but when loading a saved Minecraft world in the 3D editor, I get this:

INFO - PyMCTranslate Version 291
Gtk-Message: 17:38:41.281: Failed to load module "xapp-gtk3-module"
INFO - Loading level /home/evilsupahfly/.minecraft/saves/Otherwhere
INFO - Loading level /home/evilsupahfly/.minecraft/saves/Otherwhere
CRITICAL - NotImplementedError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/framework/pages/world_page.py", line 178, in _enable_page
    self.GetPage(page).enable()
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/edit.py", line 69, in enable
    self._canvas = EditCanvas(self, self._world)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/api/canvas/edit_canvas.py", line 150, in __init__
    super().__init__(parent, world)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/api/canvas/base_edit_canvas.py", line 63, in __init__
    super().__init__(parent)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/opengl/canvas/event_canvas.py", line 15, in __init__
    super().__init__(parent)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/opengl/canvas/canvas.py", line 41, in __init__
    display_attributes = GLAttributes()
                         ^^^^^^^^^^^^^^
SystemError: <class 'wx._glcanvas.GLAttributes'> returned a result with an exception set

CRITICAL - NotImplementedError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/framework/pages/world_page.py", line 178, in _enable_page
    self.GetPage(page).enable()
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/edit.py", line 69, in enable
    self._canvas = EditCanvas(self, self._world)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/api/canvas/edit_canvas.py", line 150, in __init__
    super().__init__(parent, world)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/api/canvas/base_edit_canvas.py", line 63, in __init__
    super().__init__(parent)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/opengl/canvas/event_canvas.py", line 15, in __init__
    super().__init__(parent)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/opengl/canvas/canvas.py", line 41, in __init__
    display_attributes = GLAttributes()
                         ^^^^^^^^^^^^^^
SystemError: <class 'wx._glcanvas.GLAttributes'> returned a result with an exception set

CRITICAL - NotImplementedError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/framework/pages/world_page.py", line 178, in _enable_page
    self.GetPage(page).enable()
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/edit.py", line 69, in enable
    self._canvas = EditCanvas(self, self._world)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/api/canvas/edit_canvas.py", line 150, in __init__
    super().__init__(parent, world)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/api/canvas/base_edit_canvas.py", line 63, in __init__
    super().__init__(parent)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/opengl/canvas/event_canvas.py", line 15, in __init__
    super().__init__(parent)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/opengl/canvas/canvas.py", line 41, in __init__
    display_attributes = GLAttributes()
                         ^^^^^^^^^^^^^^
SystemError: <class 'wx._glcanvas.GLAttributes'> returned a result with an exception set

During handling of the above exception, another exception occurred:

NotImplementedError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/framework/pages/world_page.py", line 178, in _enable_page
    self.GetPage(page).enable()
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/edit.py", line 69, in enable
    self._canvas = EditCanvas(self, self._world)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/api/canvas/edit_canvas.py", line 150, in __init__
    super().__init__(parent, world)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/api/canvas/base_edit_canvas.py", line 63, in __init__
    super().__init__(parent)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/opengl/canvas/event_canvas.py", line 15, in __init__
    super().__init__(parent)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/opengl/canvas/canvas.py", line 41, in __init__
    display_attributes = GLAttributes()
                         ^^^^^^^^^^^^^^
SystemError: <class 'wx._glcanvas.GLAttributes'> returned a result with an exception set

CRITICAL - NotImplementedError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/framework/pages/world_page.py", line 178, in _enable_page
    self.GetPage(page).enable()
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/edit.py", line 69, in enable
    self._canvas = EditCanvas(self, self._world)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/api/canvas/edit_canvas.py", line 150, in __init__
    super().__init__(parent, world)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/api/canvas/base_edit_canvas.py", line 63, in __init__
    super().__init__(parent)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/opengl/canvas/event_canvas.py", line 15, in __init__
    super().__init__(parent)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/opengl/canvas/canvas.py", line 41, in __init__
    display_attributes = GLAttributes()
                         ^^^^^^^^^^^^^^
SystemError: <class 'wx._glcanvas.GLAttributes'> returned a result with an exception set

During handling of the above exception, another exception occurred:

NotImplementedError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/framework/pages/world_page.py", line 178, in _enable_page
    self.GetPage(page).enable()
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/edit.py", line 69, in enable
    self._canvas = EditCanvas(self, self._world)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/api/canvas/edit_canvas.py", line 150, in __init__
    super().__init__(parent, world)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/programs/edit/api/canvas/base_edit_canvas.py", line 63, in __init__
    super().__init__(parent)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/opengl/canvas/event_canvas.py", line 15, in __init__
    super().__init__(parent)
  File "/app/lib/python3.11/site-packages/amulet_map_editor/api/opengl/canvas/canvas.py", line 41, in __init__
    display_attributes = GLAttributes()
                         ^^^^^^^^^^^^^^
SystemError: <class 'wx._glcanvas.GLAttributes'> returned a result with an exception set


(amulet_map_editor:2): GLib-GObject-CRITICAL **: 17:46:26.625: ../gobject/gsignal.c:2778: instance '0x5d981f7eaca0' has no handler with id '4068'

It looks to me like there was some issue with wxPython creating the 3D map canvas, but I’ll be honest here - I have no idea what all this means, or even where to begin when trying to fix it.

So I figured I would do the same thing that the Flatpak builder does, and install Amulet with PIP. Well, that’s when I get this other error:

Traceback (most recent call last):
  File "<frozen runpy>", line 189, in _run_module_as_main
  File "<frozen runpy>", line 148, in _get_module_details
  File "<frozen runpy>", line 112, in _get_module_details
  File "/home/evilsupahfly/python-virtual-environs/amulet/lib/python3.12/site-packages/amulet_map_editor/__init__.py", line 27, in <module>
    from amulet_map_editor.api.framework.app import open_level, close_level
  File "/home/evilsupahfly/python-virtual-environs/amulet/lib/python3.12/site-packages/amulet_map_editor/api/framework/__init__.py", line 1, in <module>
    from .app import AmuletApp
  File "/home/evilsupahfly/python-virtual-environs/amulet/lib/python3.12/site-packages/amulet_map_editor/api/framework/app.py", line 1, in <module>
    import wx
  File "/home/evilsupahfly/python-virtual-environs/amulet/lib/python3.12/site-packages/wx/__init__.py", line 17, in <module>
    from wx.core import *
  File "/home/evilsupahfly/python-virtual-environs/amulet/lib/python3.12/site-packages/wx/core.py", line 12, in <module>
    from ._core import *
ImportError: /home/evilsupahfly/python-virtual-environs/amulet/lib/python3.12/site-packages/wx/_core.cpython-312-x86_64-linux-gnu.so: undefined symbol: _Py_NegativeRefcount

I’ve been to the application developer who sent me to Flatpak, and the Flatpak people said I should talk to Python, and now I’m here because somebody at Python said it’s not them, it’s you.

So, can somebody help me understand what’s going here? The Flatpak version of the app actually runs just fine, until you load the 3D canvas for the Minecraft world. Then it crashes. Running the base application generates an instantly fatal error right out of the box and doesn’t even load the GUI.

I don’t have any experience of this area (I don’t even use any Flatpaks).

I did a search of the first error message:

Gtk-Message: 17:38:41.281: Failed to load module "xapp-gtk3-module"

and found this article: How To Fix "Failed to load module xapp-gtk3-module" Error in Ubuntu 20.04 | DeviceTests

Do the answers given there help?

It’s been a long time since I was, but the problem was partly caused because the version of Python I was using was too new. Reverting to an older version resolved the issue with “_Py_NegativeRefcount”. A fix was introduced in Python 3.13 which resolves this going forward, so I can’t use 3.12, but almost anything else from 3.9 on up is fine.

The xapp issue wasn’t fatal and only arises because my Flatpak adheres to the FreeDesktop standard that allows it to run almost seamlessly on either GTK or KDE. Aside from bundled textures not loading for Water and Lava, and the interface flickering, the Amulet Minecraft Map Editor: Flatpak Edition runs as expected, provided you’re not trying to use Python 3.12.