Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on status_bar.statusItemWithLength_ #575

Open
lezgomatt opened this issue Oct 24, 2023 · 2 comments
Open

Crash on status_bar.statusItemWithLength_ #575

lezgomatt opened this issue Oct 24, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@lezgomatt
Copy link

lezgomatt commented Oct 24, 2023

Describe the bug

The following code:

status_bar = NSStatusBar.systemStatusBar()
status_item = status_bar.statusItemWithLength_(NSVariableStatusItemLength)

crashes with the error:

-[_NSViewBackingLayer NS_setView:]: unrecognized selector sent to instance 0x600003e43ed0

The app terminates terminated by signal SIGTRAP (Trace or breakpoint trap) or for some illegal hardware instruction.

Platform information

  • Python version: Python 3.10.5
  • How was python installed: nix
  • macOS version: Ventura

To Reproduce

See description above.

Expected behavior

It should work, and not crash.

Additional context

@lezgomatt lezgomatt added the bug Something isn't working label Oct 24, 2023
@lezgomatt lezgomatt changed the title Crash on status_bar.statusItemWithLength_(NSVariableStatusItemLength) Crash on status_bar.statusItemWithLength_ Oct 24, 2023
@ronaldoussoren
Copy link
Owner

This is most likely not a bug in PyObjC, but Cocoa being annoyingly crash prone when using GUI code when the app isn't initialised fully enough.

from Cocoa import NSStatusBar, NSVariableStatusItemLength, NSApplication

NSApplication.sharedApplication()
status_bar = NSStatusBar.systemStatusBar()
status_item = status_bar.statusItemWithLength_(NSVariableStatusItemLength)
print(f"{status_item=}")

This script works on my system (macOS 14.3.1, M1 laptop), but crashes with Assertion failed: (CGAtomicGet(&is_initialized)), function CGSConnectionByID, file CGSConnection.mm, line 419. when I leave out the call to NSApplication.sharedApplication().

What the context in which the code is called?

@lezgomatt
Copy link
Author

lezgomatt commented Feb 12, 2024

Hi @ronaldoussoren, thanks for sharing that snippet! I can confirm that your snippet works on my machine as well. It looks like my issue is related to how I imported the library (but the error doesn't occur on import). The following snippet breaks:

from Foundation import *
from AppKit import *

NSApplication.sharedApplication()
status_bar = NSStatusBar.systemStatusBar()
status_item = status_bar.statusItemWithLength_(NSVariableStatusItemLength)
print(f"{status_item=}")

FWIW it works on v8. Replacing import * with the specific imports fixes the issue (and speed things up too).

lezgomatt added a commit to lezgomatt/ezntfs that referenced this issue Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants