lordmauve / wasabi2d

Cutting-edge 2D game framework for Python
https://wasabi2d.readthedocs.io/
GNU Lesser General Public License v3.0
154 stars 24 forks source link

Wasabi2d crashes at startup using only the quickstart code Ubuntu 20.04 #58

Open ardunster opened 3 years ago

ardunster commented 3 years ago

I have a file with only the quickstart code:

from wasabi2d import Scene, run

scene = Scene()

# The rest of your code goes here.

run()  # keep this at the end of the file

I set up a new venv to try to work with Wasabi2d. I have tried in both Python 3.8.2 and 3.7.7 using pip install wasabi2d to get dependencies. Both environments gave no errors on running pip.

In either venv I get the following traceback error (with different memory addresses) when attempting to run the above code:

Traceback (most recent call last):
  File "wasabi2dtest.py", line 3, in <module>
    scene = Scene()
  File "/home/anna/venvs/py37wasabi2d/lib/python3.7/site-packages/wasabi2d/scene.py", line 92, in __init__
    ctx = self.ctx = self._make_context(width, height)
  File "/home/anna/venvs/py37wasabi2d/lib/python3.7/site-packages/wasabi2d/scene.py", line 165, in _make_context
    depth=24
pygame.error: Could not create GL context: GLXBadFBConfig
Exception ignored in: <function Scene.__del__ at 0x7ff8709a2830>
Traceback (most recent call last):
  File "/home/anna/venvs/py37wasabi2d/lib/python3.7/site-packages/wasabi2d/scene.py", line 132, in __del__
    self.release()
  File "/home/anna/venvs/py37wasabi2d/lib/python3.7/site-packages/wasabi2d/scene.py", line 121, in release
    self.layers.clear()
AttributeError: 'Scene' object has no attribute 'layers'

pip freeze on 3.7.7:

bresenham==0.2.1
glcontext==2.2.0
mapbox-earcut==0.12.10
moderngl==5.6.1
multipledispatch==0.6.0
numpy==1.19.1
pygame==2.0.0.dev10
pyrr==0.10.3
six==1.15.0
sortedcontainers==2.2.2
wasabi2d==1.4.0

pip freeze on 3.8.2 (has a few more things I was working with in regards to the project I intended to use wasabi on):

appdirs==1.4.4
black==20.8b1
bresenham==0.2.1
click==7.1.2
flake8==3.8.3
glcontext==2.2.0
mapbox-earcut==0.12.10
mccabe==0.6.1
moderngl==5.6.1
multipledispatch==0.6.0
mypy-extensions==0.4.3
numpy==1.19.1
pathspec==0.8.0
pycodestyle==2.6.0
pyflakes==2.2.0
pygame==2.0.0.dev10
pyrr==0.10.3
regex==2020.7.14
six==1.15.0
sortedcontainers==2.2.2
toml==0.10.1
typed-ast==1.4.1
typing-extensions==3.7.4.3
wasabi2d==1.4.0

System info:

System:
  Host: stormtrooper-ubuntu Kernel: 5.4.0-42-generic x86_64 bits: 64 
  Desktop: Gnome 3.36.4 Distro: Ubuntu 20.04.1 LTS (Focal Fossa) 
Machine:
  Type: Desktop Mobo: ASUSTeK model: P7P55D-E v: Rev 1.xx 
  serial: <superuser/root required> BIOS: American Megatrends v: 1601 
  date: 06/26/2012 
CPU:
  Topology: Quad Core model: Intel Core i5 760 bits: 64 type: MCP 
  L2 cache: 8192 KiB 
  Speed: 1215 MHz min/max: 1200/2801 MHz Core speeds (MHz): 1: 1204 2: 1204 
  3: 1204 4: 1204 
Graphics:
  Device-1: AMD Barts PRO [Radeon HD 6850] driver: radeon v: kernel 
  Display: x11 server: X.Org 1.20.8 driver: radeon 
  resolution: 1920x1080~60Hz 
  OpenGL: renderer: AMD BARTS (DRM 2.50.0 / 5.4.0-42-generic LLVM 10.0.0) 
  v: 3.3 Mesa 20.0.8 
Audio:
  Device-1: Intel 5 Series/3400 Series High Definition Audio 
  driver: snd_hda_intel 
  Device-2: AMD Barts HDMI Audio [Radeon HD 6790/6850/6870 / 7720 OEM] 
  driver: snd_hda_intel 
  Device-3: Logitech Webcam C310 type: USB driver: snd-usb-audio,uvcvideo 
  Sound Server: ALSA v: k5.4.0-42-generic 
Network:
  Device-1: Qualcomm Atheros AR93xx Wireless Network Adapter driver: ath9k 
  IF: wlp7s0 state: up mac: d4:6e:0e:10:4b:a9 
Drives:
  Local Storage: total: 1.47 TiB used: 740.26 GiB (49.1%) 
  ID-1: /dev/sda vendor: Samsung model: SSD 860 EVO 500GB size: 465.76 GiB 
  ID-2: /dev/sdb vendor: Western Digital model: WD1003FZEX-00K3CA0 
  size: 931.51 GiB 
  ID-3: /dev/sdc vendor: PNY model: CS900 120GB SSD size: 111.79 GiB 
Partition:
  ID-1: / size: 109.53 GiB used: 30.99 GiB (28.3%) fs: ext4 dev: /dev/sdc1 
Sensors:
  System Temperatures: cpu: 35.5 C mobo: 30.0 C gpu: radeon temp: 42 C 
  Fan Speeds (RPM): cpu: 1480 psu: 0 case-1: 1548 case-2: 0 
Info:
  Processes: 272 Uptime: 3h 43m Memory: 19.55 GiB used: 3.25 GiB (16.6%) 
  Shell: bash inxi: 3.0.38 

I think the key part of the error is the GL error: pygame.error: Could not create GL context: GLXBadFBConfig GL is working fine in other software. The quickstart code works fine in a conda environment on my OSX laptop. But it won't work on the Ubuntu desktop.

lordmauve commented 3 years ago

From https://stackoverflow.com/questions/39213757/glfw-cannot-create-a-window-glx-failed-to-create-context-glxbadfbconfig it looks like this is because your graphics driver doesn't support OpenGL 4.1.

Indeed it says 3.3 here:

OpenGL: renderer: AMD BARTS (DRM 2.50.0 / 5.4.0-42-generic LLVM 10.0.0) 
  v: 3.3 Mesa 20.0.8

I wonder if there are better drivers for your card? I will do some research.

lordmauve commented 3 years ago

There's a video here that talks about doing driver upgrades to get OpenGL 4.1 on AMD graphics. It's for older Ubuntu and newer hardware but maybe it will have useful information: https://youtu.be/M4GPgw2wyzg

ardunster commented 3 years ago

I subscribed to the oibaf ppa https://launchpad.net/~oibaf/+archive/ubuntu/graphics-drivers which gives me the most recent Mesa version (20.3.0-devel), however does not update my core profile version, because AMD "Barts" doesn't actually support FP64 at a hardware level, which seems to be required for any current Mesa driver to support OpenGL 4 (per the information here: https://www.phoronix.com/scan.php?page=news_item&px=R600g-Lands-FP64-Native) However it is doable at a software level and not something that is typically used.

For reference, Pygame itself has no problem opening a GL context on this machine with a Mesa driver. Neither do I have any problem with other games. After spending a bunch of time digging and troubleshooting, I found that I can launch the wasabi2d scene with an override for my Mesa context: MESA_GL_VERSION_OVERRIDE=4.3 python3 wasabi2dtest.py (thanks to https://askubuntu.com/questions/850900/why-is-my-opengl-version-stuck-at-3-0-despite-new-hardware-software). I think the issue is that lines 135-139 in scene.py call for an openGL 4 context:

        """Create the ModernGL context."""
        glconfig = {
            'GL_CONTEXT_MAJOR_VERSION': 4,
            'GL_CONTEXT_PROFILE_MASK': pygame.GL_CONTEXT_PROFILE_CORE,
        }

Does wasabi actually require 4 or can it run on older versions? As I mentioned, pygame itself works fine without any overrides.

It seems I'll be able to work on this project using an override every time I call my script, but that seems like an awfully clunky workaround. I think the proprietary driver has support for OpenGL 4.1 but would rather not use if I can avoid it. Maybe there's a way to set a permanent override.

ardunster commented 3 years ago

Are there features being used in wasabi2d that are actually exclusive to OpenGL4? I assume there's some reason you have the context require=410 set. But altering the require and glconfig lines I can get the same behavior in my test scene as I can using the Mesa override I mentioned above (that is, it will load and render, but text displays funny). If Wasabi2D requires 4.1, it may not be the best choice for our project (generally aimed at broadest possible accessibility).