Quartz.CGBeginDisplayConfiguration() doesn't work

Issue #132 closed
Pierce Darragh created an issue

On Apple's Python in 10.10, Homebrew Python in 10.10, and Apple's Python in 10.11, the Quartz module's CGBeginDisplayConfiguration call exits prematurely:

>>> (error, config_ref) = Quartz.CGBeginDisplayConfiguration(None)
Assertion failed: (did_initialize), function CGS_REQUIRE_INIT, file Desktop/CGInitialization.c, line 40.
Abort trap: 6

And then the interpreter exits with code 134.

I believe I'm making the call correctly, but it always results in this error across multiple devices. Any ideas?

Comments (7)

  1. Pierce Darragh reporter

    This is curious... if I make a call for the main display's bounds, the setup call works:

    >>> import Quartz
    >>> Quartz.CGDisplayBounds(Quartz.CGMainDisplayID())
    <NSRect origin=<NSPoint x=0.0 y=0.0> size=<NSSize width=1680.0 height=1050.0>>
    >>> (error, config_ref) = Quartz.CGBeginDisplayConfiguration(None)

    But if I don't make that call to CGDisplayBounds in advance, it still fails just like in the initial post.

    This is counterintuitive, since there's no information going into the CGBeginDisplayConfiguration call that came out of the CGDisplayBounds call. Is there some static variable getting set up in the background that CGBeginDisplayConfiguration depends on?

  2. Ronald Oussoren repo owner

    The crash indicates that Apple's CoreGraphics library isn't initialized properly by the time you call the function. Do you call the function in a (command-line) script, or in a full application?

    When I look for "CGS_REQUIRE_INIT" on Google I see more projects that have this problem.

    BTW. What happens if you call just "Quartz.CGMainDisplayID()" (and not CGDisplayBounds)?

  3. Pierce Darragh reporter

    I'm writing a script to handle setting display configurations in a distributed environment, so the issue presents itself when running a Python script (and also in the interpreter when I'm testing methods).

    Calling Quartz.CGMainDisplayID() on its own also mitigates the issue, so that's nice.

    If the issue is one of initialization, would it be possible to just initialize the CoreGraphics library when you import Quartz? (I haven't looked through the PyObjC code to see how it works, so I'm just taking a stab at things here.)

  4. Ronald Oussoren repo owner

    Libraries are supposed to initialise themselves when they are used. The function CoreGraphics uses for that isn't a public API, and for some reason CGBeginDisplayConfiguration no longer contains a call to the initialisation function. That is something that Apple likely won't fix because this isn't an issue in GUI applications :-(.

    Could you file a bug report with Apple about this if you have an Apple developer account (preferably with a small C program that demonstrates the problem, that's more likely to get the attention of Apple). I'll do so as well, but it helps when more people report the issue, and especially when you have a good usecase for this (such as your script for configuring displays).

    I will add a call to Quartz.CGMainDisplayID() to the Quartz module as a workaround for this issue in the next release of PyObjC.

    BTW. Thanks for the report.

  5. Pierce Darragh reporter

    Ah, wow. That's too bad, but at least it's not your fault!

    Could you file a bug report with Apple about this

    Yeah, we have an enterprise support rep so I'll also bug Apple about it (ha! pun!) through those channels.

    Thanks for implementing the workaround and the quick replies to get to the bottom of this. This module is super helpful and we're thankful that you provide it.


  6. Log in to comment