"Could not open window" on macOS Mojave

Hello,

I am having some trouble getting the latest panda3d to work on macOS Mojave. Running the asteroids example yields the following results:

$ python main.py 
Known pipe types:
  CocoaGraphicsPipe
(all display modules loaded.)
:display:cocoadisplay(error): Could not find a usable pixel format.
:ShowBase(warning): Unable to open 'onscreen' window.
Traceback (most recent call last):
  File "main.py", line 398, in <module>
    demo = AsteroidsDemo()
  File "main.py", line 92, in __init__
    ShowBase.__init__(self)
  File "/Developer/Panda3D/direct/showbase/ShowBase.py", line 274, in __init__
    self.openDefaultWindow(startDirect = False, props=props)
  File "/Developer/Panda3D/direct/showbase/ShowBase.py", line 940, in openDefaultWindow
    self.openMainWindow(*args, **kw)
  File "/Developer/Panda3D/direct/showbase/ShowBase.py", line 976, in openMainWindow
    self.openWindow(*args, **kw)
  File "/Developer/Panda3D/direct/showbase/ShowBase.py", line 725, in openWindow
    raise Exception('Could not open window.')
Exception: Could not open window.

Let me know if I can provide any additional info to help debug.

Thanks.

Could be related to https://github.com/panda3d/panda3d/pull/551

Try adding those lines at the top or main.py and see if it works ?

from panda3d.core import loadPrcFileData
loadPrcFileData("", "depth-bits 16\n")

Nope. Same exact error.

Do you have a multi-monitor or multi-GPU set-up? Can you run other OpenGL applications? Does setting gl-version 3 2 in your Config.prc file do anything?

I tried setting that both using Config.prc and loadPrcFileData, but no joy.

However, while browsing the Config.prc I found:

framebuffer-hardware #t
framebuffer-software #f

When I commented both out (since “If you don’t set either, it will use whatever’s available.”), I still get the save exact error. However when I reversed the values setting software to true and hardware to false, Everything works perfectly.

One particular thing to note of my configuration is that the macOS is run inside of a VMWare virtual machine.

I tested my OpenGL using a OpenGL Extensions Viewer app and all tests up to OpenGL version 4.1 completed successfully. Although 4 and 4.1 where extremely slow (to be expected in a VM).

OK, that’s the piece of information we were missing. Panda is behaving as expected, then. The default values for those variables are used if you omit them from Config.prc, but the default values are the same as the ones you see in Config.prc. You should be able to explicitly set both framebuffer-hardware and framebuffer-software yourself to true or false as desired if you don’t want to restrict yourself to a hardware framebuffer.

I am curious, is there a reason software rendering is explicitly disabled by default?

Also, reading the comments in the Config.prc:

# The framebuffer-hardware flag forces it to use an accelerated driver.
# The framebuffer-software flag forces it to use a software renderer.
# If you don't set either, it will use whatever's available.

I am lead to believe that if both are omitted, the default behavior is to allow both, but prefer hardware, which seems like a very sensible option. I’m guessing this comment is incorrect then?

Also, when I set both software and hardware to false, the example also seems to also work, making me assume that its behavior is equivalent to setting both to true. Maybe this is the intended default setting? Since that way if someone needs to explicitly allow only one of the options they only need to enable it.

The reason it’s disabled by default is because for the majority of games, software rendering is unusably slow, and usually a sign that the user did not install drivers correctly.

I think the comment meant “if both are set to false”, and I will clarify the language to that effect.

1 Like

Hi, community. One user of my game encountered this problem on his macOS Big Sur with M1 chip and python3.9.
This is his error message:

(pgdrive) ➜  ~ python -m pgdrive.examples.enjoy_expert
Successfully registered the following environments: ['PGDrive-test-v0', 'PGDrive-validation-v0', 'PGDrive-v0', 'PGDrive-10envs-v0', 'PGDrive-1000envs-v0', 'PGDrive-training0-v0', 'PGDrive-training1-v0', 'PGDrive-training2-v0'].
Known pipe types:
  CocoaGraphicsPipe
(all display modules loaded.)
:display:cocoadisplay(error): Could not find a usable pixel format.
:ShowBase(warning): Unable to open 'onscreen' window.
Traceback (most recent call last):
  File "/Users/namdar/opt/miniconda3/envs/pgdrive/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/namdar/opt/miniconda3/envs/pgdrive/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/namdar/opt/miniconda3/envs/pgdrive/lib/python3.9/site-packages/pgdrive/examples/enjoy_expert.py", line 15, in <module>
    obs = env.reset()
  File "/Users/namdar/opt/miniconda3/envs/pgdrive/lib/python3.9/site-packages/pgdrive/envs/pgdrive_env.py", line 250, in reset
    self.lazy_init()  # it only works the first time when reset() is called to avoid the error when render
  File "/Users/namdar/opt/miniconda3/envs/pgdrive/lib/python3.9/site-packages/pgdrive/envs/pgdrive_env.py", line 149, in lazy_init
    self.pg_world = PGWorld(self.pg_world_config)
  File "/Users/namdar/opt/miniconda3/envs/pgdrive/lib/python3.9/site-packages/pgdrive/world/pg_world.py", line 104, in __init__
    super(PGWorld, self).__init__(windowType=self.mode)
  File "/Users/namdar/opt/miniconda3/envs/pgdrive/lib/python3.9/site-packages/direct/showbase/ShowBase.py", line 339, in __init__
    self.openDefaultWindow(startDirect = False, props=props)
  File "/Users/namdar/opt/miniconda3/envs/pgdrive/lib/python3.9/site-packages/direct/showbase/ShowBase.py", line 1021, in openDefaultWindow
    self.openMainWindow(*args, **kw)
  File "/Users/namdar/opt/miniconda3/envs/pgdrive/lib/python3.9/site-packages/direct/showbase/ShowBase.py", line 1056, in openMainWindow
    self.openWindow(*args, **kw)
  File "/Users/namdar/opt/miniconda3/envs/pgdrive/lib/python3.9/site-packages/direct/showbase/ShowBase.py", line 801, in openWindow
    raise Exception('Could not open window.')
Exception: Could not open window.
(pgdrive) ➜  ~ python -m pgdrive.examples.enjoy_expert

I am not sure if this is related to the M1 chip of the new Macbook.

Hmm, are there any particular framebuffer properties you are requesting in your Config.prc, other than the defaults? The system for requesting framebuffer formats is a little more strict on macOS (for reasons out of our control).

We’re talking things like depth bits, stencil bits, etc.

Thank you rdb, and these are the extra Config loaded in the showbase instance:

  • loadPrcFileData("", “window-title {}”.format(PG_EDITION))
  • loadPrcFileData("", “framebuffer-multisample 1”)
  • loadPrcFileData("", “multisamples 8”)
  • loadPrcFileData("", ‘bullet-filter-algorithm groups-mask’)
  • loadPrcFileData("", “audio-library-name null”)
  • loadPrcFileData("", “want-pstats 1”)
  • loadPrcFileData("", “win-size {} {}”.format(*self.pg_config[“window_size”]))
  • loadPrcFileData("", “threading-model Cull/Draw”)
  • loadPrcFileData("", “compressed-textures 1”)

It seems that only one item is related to the framebuffer. Besides, we have tested our program on several MacOS machines, except the latest MacBook with the M1 chip. So I suspect that some new features of the new MacBook cause this problem.

Try taking out both multisample lines and see if it works hen.