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

No Displays from CGGetOnlineDisplayList when using NAPI #31328

Closed
kusti8 opened this issue Jan 12, 2020 · 7 comments
Closed

No Displays from CGGetOnlineDisplayList when using NAPI #31328

kusti8 opened this issue Jan 12, 2020 · 7 comments
Labels
macos Issues and PRs related to the macOS platform / OSX.

Comments

@kusti8
Copy link

kusti8 commented Jan 12, 2020

Version: 13.6.0
Platform: Darwin kusti8s-iMac.local 19.0.0 Darwin Kernel Version 19.0.0: Wed Sep 25 20:18:50 PDT 2019; root:xnu-6153.11.26~2/RELEASE_X86_64 x86_64
Subsystem: NAPI

I have a really interesting issue that first came up when I tried to port my wxWidgets bindings with NAPI to Mac. It kept on reporting that 0 displays were detected. Running it through lldb shows the CGGetOnlineDisplayList function returns 0 displays.

I created a very minimal test example here:

make.sh

c++ -fno-exceptions '-DNAPI_DISABLE_CPP_EXCEPTIONS' '-DNODE_GYP_MODULE_NAME=test' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DNAPI_VERSION=4' '-D_UNICODE' '-DUNICODE' '-DBUILDING_NODE_EXTENSION' -I/Users/kusti8/Library/Caches/node-gyp/13.6.0/include/node -I/Users/kusti8/Library/Caches/node-gyp/13.6.0/src -I/Users/kusti8/Library/Caches/node-gyp/13.6.0/deps/openssl/config -I/Users/kusti8/Library/Caches/node-gyp/13.6.0/deps/openssl/openssl/include -I/Users/kusti8/Library/Caches/node-gyp/13.6.0/deps/uv/include -I/Users/kusti8/Library/Caches/node-gyp/13.6.0/deps/zlib -I/Users/kusti8/Library/Caches/node-gyp/13.6.0/deps/v8/include -I/Users/kusti8/Documents/GitHub/node-wx-napi/node_modules/node-addon-api  -Os -gdwarf-2 -mmacosx-version-min=10.9 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -fno-common -fvisibility-inlines-hidden -MMD -MF main.o.d.raw   -c -o main.o main.cpp
c++ -bundle -undefined dynamic_lookup -Wl,-no_pie -Wl,-search_paths_first -mmacosx-version-min=10.9 -arch x86_64 -L. -stdlib=libc++  -o out.node main.o -framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework System -framework OpenGL -framework Security -framework ApplicationServices -framework WebKit -framework QuartzCore -framework CoreGraphics

And then main.cpp

#include <ApplicationServices/ApplicationServices.h>
#include <napi.h>

Napi::Value desktopSize(const Napi::CallbackInfo &info)
{

    uint32_t numDisplays = 0;
    CGGetOnlineDisplayList(0, NULL, &numDisplays);
    printf("Displays %d\n", numDisplays);
    printf("Displays %d\n", numDisplays);

    return Napi::Value();
}

Napi::Object Init(Napi::Env env, Napi::Object exports)
{
    exports.Set("desktopSize", Napi::Function::New(env, desktopSize));
    return exports;
}

NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init)

int main(int argc, char **argv)
{
    uint32_t numDisplays = 0;
    CGGetOnlineDisplayList(0, NULL, &numDisplays);
    printf("Displays %d\n", numDisplays);
    return 0;
}

When calling this through node, displays is printed as 0. However, when I remove -bundle in the linking phase, comment out everything above int main(int argc, char **argv) and run it as an executable, it prints out the correct number of displays: 1.

I don't know anything about how Node works on the inside, but to me it looks like some sort of sandboxing thing, but I really have no idea. Or maybe I'm forgetting a compiler flag.

Thanks,
Gustav

@richardlau
Copy link
Member

Suspect this is related to libuv/libuv#2566, libuv/libuv#2568 and libuv/libuv#2593.

cc @nodejs/platform-macos

@richardlau richardlau added the macos Issues and PRs related to the macOS platform / OSX. label Jan 12, 2020
@targos targos reopened this Jan 21, 2020
@shayneoneill
Copy link

Is there an eta on this one? Its a showstopper of a bug

@addaleax
Copy link
Member

/cc @cjihrig @nodejs/libuv

@cjihrig
Copy link
Contributor

cjihrig commented Jan 23, 2020

I can cut a libuv 1.34.2 release. It would still take two days to land and then however long after that to make it into a Node release.

cjihrig added a commit to cjihrig/node that referenced this issue Jan 23, 2020
Notable changes:

- SetApplicationDaemon() is no longer called on macOS.
- uv_interface_addresses() is implemented on IBMi.
- The return value of uv__open_cloexec() is now handled
  properly.
- A race condition in fsevents has been fixed.

Fixes: nodejs#31328
Fixes: nodejs/help#2099
@cjihrig
Copy link
Contributor

cjihrig commented Jan 23, 2020

libuv update in #31477. The rest is in the Node team's hands.

@Trott Trott closed this as completed in 05d350a Jan 25, 2020
codebytere pushed a commit that referenced this issue Feb 17, 2020
Notable changes:

- SetApplicationDaemon() is no longer called on macOS.
- uv_interface_addresses() is implemented on IBMi.
- The return value of uv__open_cloexec() is now handled
  properly.
- A race condition in fsevents has been fixed.

Fixes: #31328
Fixes: nodejs/help#2099

PR-URL: #31477
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BethGriggs pushed a commit to BethGriggs/node that referenced this issue Feb 26, 2020
Notable changes:

- SetApplicationDaemon() is no longer called on macOS.
- uv_interface_addresses() is implemented on IBMi.
- The return value of uv__open_cloexec() is now handled
  properly.
- A race condition in fsevents has been fixed.

Fixes: nodejs#31328
Fixes: nodejs/help#2099

PR-URL: nodejs#31477
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BethGriggs pushed a commit that referenced this issue Mar 2, 2020
Notable changes:

- SetApplicationDaemon() is no longer called on macOS.
- uv_interface_addresses() is implemented on IBMi.
- The return value of uv__open_cloexec() is now handled
  properly.
- A race condition in fsevents has been fixed.

Fixes: #31328
Fixes: nodejs/help#2099

PR-URL: #31477
Backport-PR-URL: #31969
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
codebytere pushed a commit that referenced this issue Mar 15, 2020
Notable changes:

- SetApplicationDaemon() is no longer called on macOS.
- uv_interface_addresses() is implemented on IBMi.
- The return value of uv__open_cloexec() is now handled
  properly.
- A race condition in fsevents has been fixed.

Fixes: #31328
Fixes: nodejs/help#2099

PR-URL: #31477
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
codebytere pushed a commit that referenced this issue Mar 17, 2020
Notable changes:

- SetApplicationDaemon() is no longer called on macOS.
- uv_interface_addresses() is implemented on IBMi.
- The return value of uv__open_cloexec() is now handled
  properly.
- A race condition in fsevents has been fixed.

Fixes: #31328
Fixes: nodejs/help#2099

PR-URL: #31477
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@zcbenz
Copy link
Contributor

zcbenz commented Apr 3, 2020

@bnoordhuis @cjihrig Can the fix be backported to Node v12? Currently all GUI bindings fail to work on macOS due to this bug.

zcbenz pushed a commit to yue/node that referenced this issue Apr 3, 2020
Notable changes:

- SetApplicationDaemon() is no longer called on macOS.
- uv_interface_addresses() is implemented on IBMi.
- The return value of uv__open_cloexec() is now handled
  properly.
- A race condition in fsevents has been fixed.

Fixes: nodejs/node#31328
Fixes: nodejs/help#2099

PR-URL: nodejs/node#31477
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@richardlau
Copy link
Member

@zcbenz a libuv update is included in the next proposed 12.x release: #32313

zcbenz pushed a commit to yue/node that referenced this issue Apr 3, 2020
Notable changes:

- SetApplicationDaemon() is no longer called on macOS.
- uv_interface_addresses() is implemented on IBMi.
- The return value of uv__open_cloexec() is now handled
  properly.
- A race condition in fsevents has been fixed.

Fixes: nodejs/node#31328
Fixes: nodejs/help#2099

PR-URL: nodejs/node#31477
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
zcbenz pushed a commit to yue/node that referenced this issue Apr 3, 2020
Notable changes:

- SetApplicationDaemon() is no longer called on macOS.
- uv_interface_addresses() is implemented on IBMi.
- The return value of uv__open_cloexec() is now handled
  properly.
- A race condition in fsevents has been fixed.

Fixes: nodejs/node#31328
Fixes: nodejs/help#2099

PR-URL: nodejs/node#31477
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
zcbenz pushed a commit to yue/node that referenced this issue Apr 3, 2020
Notable changes:

- SetApplicationDaemon() is no longer called on macOS.
- uv_interface_addresses() is implemented on IBMi.
- The return value of uv__open_cloexec() is now handled
  properly.
- A race condition in fsevents has been fixed.

Fixes: nodejs/node#31328
Fixes: nodejs/help#2099

PR-URL: nodejs/node#31477
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
macos Issues and PRs related to the macOS platform / OSX.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants