univ-of-utah-marriott-library-apple / display_manager

An open-source Python library which can modify your Mac's display settings manually or automatically.
MIT License
237 stars 18 forks source link

Assertion error at getIOKit method #33

Open Kalmat opened 10 months ago

Kalmat commented 10 months ago

Hi!

I recently managed to test in an actual macOS (I was testing in a macOS VM, in which many features, including your module, was not working).

I am running this on mac mini with Catalina (10.15.7) and Python 3.8.2 (let me know if you need other details)

When executing this:

import Quartz

from ._display_manager_lib import Display  # display_manager_lib.py is directly taken from your repo, and not modified at all

self.handle = Quartz.CGMainDisplayID()
self._dm = Display(self.handle)

I receive this error:

2023-10-16 21:26:19.022 Python[502:4685] *** Assertion failure in +[UINSServiceViewController initialize], /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/ViewBridge/ViewBridge-468/UINSServiceViewController.m:203

The origin of this error is within getIOKit() function, but all its content is totally alien to me, sorry. There is no error if you just comment getIOKit() in Display's class __init__() method, but rationally all related functions do not work.

If, in addition, I run this:

self._dm.brightness()      # returns None
self._dm.setBrightness(50)  # This crashes (see below)

I get this error:

Traceback (most recent call last):
    File "test.py", line 12, in <module>
        mon1.setBrightness(50)
    File "/Users/Angel/Library/Python/3.8/lib/python/site-packages/pymonctl/_pymonctl_macos.py", line 320, in setBrightness
        self._dm.setBrightness(brightness)
    File "/Users/Angel/Library/Python/3.8/lib/python/site-packages/pymonctl/_display_manager_lib.py", line 449, in setBrightness
        raise DisplayError("Cannot manage brightness on display \"{}\"".format(self.tag))
pymonctl._display_manager_lib.DisplayError: Cannot manage brightness on display "main"

I know I'm using your module in a non-standard way but, if you can bring some light to this problem, I would really appreciate it!

Kalmat commented 10 months ago

Hi again!

I managed to identfy the failure point:

# Retrieve the IOKit framework
iokitBundle = objc.initFrameworkWrapper(
    "IOKit",
    frameworkIdentifier="com.apple.iokit",
    frameworkPath=objc.pathForFramework("/System/Library/Frameworks/IOKit.framework"),
    globals=globals()
    )

It always crashes in Catalina, despite the Python version or other circumstances. Perhaps in Catalina this function should be invoked in a different way, but unfortunately I found nothing about it. If, by any chance, you know how to solve this in Catalina, or you know any place I can investigate, I would really appreciate your help!

uurazzle commented 10 months ago

Hello @Kalmat,

Appreciate your troubleshooting efforts and feedback. Unfortunately, due to current constraints in terms of time, resources, and priorities, we won't be able to address this project or issue at the moment. Rest assured, we've noted it down in our backlog, and we'll aim to tackle it in the future if circumstances permit. Thank you for your understanding.

Kalmat commented 10 months ago

Hi @uurazzle! Thank you for your reply and, especially, for your work and for sharing it!

I will wait until you have time, of course. In the meantime, I will verify macOS version before invoking the lib in order to avoid crashes.

Thank you again!

Kalmat commented 9 months ago

Hi again! I just wanted to let you know other two issues I have detected, for whenever you plan to work on this again (of course, no hurries!). I will summarize here them all:

  1. (previous issue): crashes in Catalina when trying to instantiate Display() class
  2. (new): setBrightness() method crashes in Ventura (it didn't in a BigSur VM)
  3. (new): in an actual mac with Ventura (I upgraded from Catalina), it takes around 5 seconds to instantiate Display() class

Thank you again.