Panda3D with cefpython on macos

I’m playing around with integrating a UI info panda3D and I’m running into some weird issues on macOS. First, here’s a minimal example for reproducing my problem:

from cefpython3 import cefpython

from direct.showbase.ShowBase import ShowBase
from direct.task import Task


class MyApp(ShowBase):
    def __init__(self):
        super().__init__()
        self.disableMouse()

        self.updateTask = self.taskMgr.add(self.updateTask, 'updateTask')

    def updateTask(self, task):
        if self.mouseWatcherNode.hasMouse():
            x = self.mouseWatcherNode.getMouseX()
            y = self.mouseWatcherNode.getMouseY()
            print(x, y)
        cefpython.MessageLoopWork()
        return Task.cont


def main():
    settings = {
        "windowless_rendering_enabled": True,
    }

    switches = {
        "disable-gpu": "",
        "disable-gpu-compositing": "",
        "enable-begin-frame-scheduling": "",
    }

    cefpython.Initialize(settings=settings, switches=switches)
    app = MyApp()
    app.run()
    cefpython.Shutdown()


if __name__ == '__main__':
    main()

When I run this, the mouse positions printed out are only updated when I have a mouse button clicked on the window. Has anyone encountered this before or have any insight into what might be going on here?

As a heads up, there are quite a few gotchas when using CEF with Panda, and you may want to take a look at cefpanda to handle some of those gotchas for you.

As for your question, this looks pretty similar to how the mouse is handled for cefpanda, and that works on Linux and Windows. I wonder if there is some macOS quirk here? Can you reproduce the issue without any of the CEF code in there?

Thanks for the reply! The example works as expected on Ubuntu 16.04 and Windows 10. So the weirdness only happens on MacOS 10.15.

I looked into cefpython and what they are doing differently is initializing cefpython after initializing panda3d. If I change the example to do that, then I get an “Illegal instruction: 4” error from cefpython. I get the same error if I try the cefpanda examples.

Just tested with Panda 1.10.4.1 and cefpython3 version 0.66 on MacOS Mojave (10.14.6) and your example works out of the box, when the mouse is in the window I get the mouse position in the console.

Maybe it’s another side effect of Catalina (yikes) or you are using an older version of panda or cefpython ?

That’s interesting! (Also yes yikes Catalina). I’ll have to double-check the versions when I get home this evening, but they were both the current pip versions.

So I just checked and I can confirm that I am using panda3d==1.10.4.1 and cefpython3==66.0. @eldee When you move the mouse you actually get different numbers, right? (for me it will print the positions every task update like it should, it’s just that the mouse manager doesn’t update its position until the mouse button is pressed).

Yes, the mouse position is updated whenever I move the mouse, independently of any button pressed.

I don’t want to migrate my main Mac to catalina yet, but I’ve got an older one which I plan to upgrade this week, then I might investigate further

Alright I think I can actually reproduce this using cefpython’s pysdl example. @eldee Do you think I could get you to try it on Mojave for me? It would be a great help because then I could take this over to cefpython’s forums. It requires the following dependencies:

brew install sdl2
pip install pysdl2

You can get the cefpython repo from

https://github.com/cztomczak/cefpython.git

and then apply this diff to make the example work in python 3:

diff --git a/examples/pysdl2.py b/examples/pysdl2.py
index 74bc542..7b08645 100644
--- a/examples/pysdl2.py
+++ b/examples/pysdl2.py
@@ -169,7 +169,7 @@ def main():
     logging.debug("SDL2 initialised")
     # Create the window
     window = sdl2.video.SDL_CreateWindow(
-        'cefpython3 SDL2 Demo',
+        b'cefpython3 SDL2 Demo',
         sdl2.video.SDL_WINDOWPOS_UNDEFINED,
         sdl2.video.SDL_WINDOWPOS_UNDEFINED,
         width,
@@ -382,7 +382,7 @@ def main():
         # regulate frame rate
         if sdl2.timer.SDL_GetTicks() - startTime < 1000.0 / frameRate:
             sdl2.timer.SDL_Delay(
-                (1000 / frameRate) - (sdl2.timer.SDL_GetTicks() - startTime)
+                (1000 // frameRate) - (sdl2.timer.SDL_GetTicks() - startTime)
             )
     # User exited
     exit_app()

then go into the example directory and run it:

cd cefpython/examples
python pysdl2.py

When you have it open, the google search bar should have the cursor. Click out, then hover your mouse over the search bar and you should see the search bar highlight. (for me it only does it with the mouse button down).

Tested with :

  • MacOS 10.14.6
  • Python-3.7.5
  • sdl2-2.0.10
  • PySDL2-0.9.6
  • cefpython3-66.0

(Everything is latest from brew actually)

The search bar gets highlighted when I hover over it (without any action from the mouse button). So your guess is correct, the problem is in cef (or cefpython) under Catalina.