Skip to content

macOS Sequoia "Domain name cannot be nil or empty" #164

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

Closed
inflex opened this issue Apr 25, 2025 · 5 comments
Closed

macOS Sequoia "Domain name cannot be nil or empty" #164

inflex opened this issue Apr 25, 2025 · 5 comments

Comments

@inflex
Copy link

inflex commented Apr 25, 2025

Hopefully not wasting people's time here.

I've noticed people using my program on macOS Sequoia, either Intel or ARM are unable now to use the Save-As / Open / Folder-select NFD's and best I can see there's an error presented in the "Console".

The program itself reports "picker_folder: selection cancelled".

No issues with the code in prior macOS releases (and this is built on Catalina Intel)

Unable to display open panel (unrecognized error: Error Domain=com.apple.ViewBridge Code=14 "(null)" UserInfo={com.apple.ViewBridge.error.hint=-[NSViewServiceMarshal bootstrap:withReply:] caught NSInvalidArgumentException '*** -[NSUserDefaults setObject:forKey:inDomain:]: domain name cannot be nil or empty' with backtrace (
    "0   CoreFoundation                      __exceptionPreprocess + 176",
    "1   libobjc.A.dylib                     objc_exception_throw + 88",
    "2   Foundation                          -[NSUserDefaults(NSUserDefaults) setObject:forKey:inDomain:] + 420",
    "3   AppKit                              +[NSOSPDefaults _readFileListModeForIdentifier:inSaveMode:inDirectory:lastListForMediaBrowserMode:] + 524",
    "4   AppKit                              -[NSRemoteSavePanel(NSSavePanelLayout) _makeFinderKitView] + 416",
    "5   AppKit                              -[NSRemoteSavePanel(NSSavePanelLayout) _setupFileBrowserView] + 68",
    "6   AppKit                              -[NSRemoteSavePanel(NSSavePanelLayout) _initContentView] + 1544",
    "7   AppKit                              -[NSRemoteSavePanel initWithContentRect:styleMask:backing:defer:] + 488",
    "8   AppKit                              -[NSRemoteSavePanel initWithOptions:] + 476",
    "9   com.apple.appkit.xpc.openAndSavePan main + 708",
    "10  com.apple.appkit.xpc.openAndSavePan com.apple.appkit.xpc.openAndSavePan + 6440",
    "11  AppKit                              -[NSViewController _loadViewIfRequired] + 72",
    "12  AppKit                              __24-[NSViewController view]_block_invoke + 28",
    "13  AppKit                              NSPerformVisuallyAtomicChange + 108",
    "14  AppKit                              -[NSViewController view] + 160",
    "15  ViewBridge                          -[NSViewServiceMarshal _bootstrap:replyData:completion:] + 1308",
    "16  ViewBridge                          -[NSViewServiceMarshal bootstrap:withReply:] + 272",
    "17  CoreFoundation                      __invoking___ + 148",
    "18  CoreFoundation                      -[NSInvocation invoke] + 424",
    "19  CoreFoundation                      -[NSInvocation invokeWithTarget:] + 64",
    "20  ViewBridge                          -[NSVB_ViewServiceImplicitAnimationDecodingProxy forwardInvocation:] + 192",
    "21  CoreFoundation                      ___forwarding___ + 956",
    "22  CoreFoundation                      _CF_forwarding_prep_0 + 96",
    "23  CoreFoundation                      __invoking___ + 148",
    "24  CoreFoundation                      -[NSInvocation invoke] + 424",
    "25  CoreFoundation                      -[NSInvocation invokeWithTarget:] + 64",
    "26  ViewBridge                          -[NSVB_QueueingProxy forwardInvocation:] + 308",
    "27  CoreFoundation                      ___forwarding___ + 956",
    "28  CoreFoundation                      _CF_forwarding_prep_0 + 96",
    "29  CoreFoundation                      __invoking___ + 148",
    "30  CoreFoundation                      -[NSInvocation invoke] + 424",
    "31  CoreFoundation                      -[NSInvocation invokeWithTarget:] + 64",
    "32  CoreFoundation                      ___forwarding___ + 956",
    "33  CoreFoundation                      _CF_forwarding_prep_0 + 96",
    "34  CoreFoundation                      __invoking___ + 148",
    "35  CoreFoundation                      -[NSInvocation invoke] + 424",
    "36  ViewBridge                          __deferNSXPCInvocationOntoMainThread_block_invoke + 132",
    "37  ViewBridge                          __wrapBlockWithVoucher_block_invoke + 56",
    "38  ViewBridge                          deferredBlockOpportunity_block_invoke_2 + 356",
    "39  CoreFoundation                      __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 28",
    "40  CoreFoundation                      __CFRunLoopDoBlocks + 352",
    "41  CoreFoundation                      __CFRunLoopRun + 2384",
    "42  CoreFoundation                      CFRunLoopRunSpecific + 572",
    "43  HIToolbox                           RunCurrentEventLoopInMode + 324",
    "44  HIToolbox                           ReceiveNextEventCommon + 676",
    "45  HIToolbox                           _BlockUntilNextEventMatchingListInModeWithFilter + 76",
    "46  AppKit                              _DPSNextEvent + 684",
    "47  AppKit                              -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 688",
    "48  ViewBridge                          __77-[NSViewServiceApplication vbNextEventMatchingMask:untilDate:inMode:dequeue:]_block_invoke + 148",
    "49  ViewBridge                          -[NSViewServiceApplication _withToxicEventMonitorPerform:] + 152",
    "50  ViewBridge                          -[NSViewServiceApplication vbNextEventMatchingMask:untilDate:inMode:dequeue:] + 168",
    "51  ViewBridge                          -[NSViewServiceApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 100",
    "52  AppKit                              -[NSApplication run] + 480",
    "53  AppKit                              NSApplicationMain + 880",
    "54  libxpc.dylib                        _xpc_objc_main + 816",
    "55  libxpc.dylib                        _xpc_main + 40",
    "56  libxpc.dylib                        _xpc_copy_xpcservice_dictionary + 0",
    "57  ViewBridge                          xpc_connection_handler + 0",
    "58  ViewBridge                          NSViewServiceMain + 360",
    "59  com.apple.appkit.xpc.openAndSavePan main + 156",
    "60  dyld                                start + 6000"
), com.apple.ViewBridge.error.description=NSViewBridgeErrorServiceBootstrap})

Function that is called is this...

std::filesystem::path BoardView::picker_folder( std::filesystem::path defaultPath ){

	char dp[4096];

	std::filesystem::path filename;
	NFD_Init();
	nfdpickfolderu8args_t args = { NULL,  { 0, NULL } };
	nfdu8char_t *outPath;

	filename.clear();

	if (!defaultPath.empty()) {
		snprintf(dp, sizeof(dp), "%s", defaultPath.string().c_str());
		args.defaultPath = dp;
	} else {
		snprintf(dp, sizeof(dp), "%s", cwd.string().c_str());
		args.defaultPath = dp;
	}

	NFD_GetNativeWindowFromSDLWindow(mainWindow /* SDL_Window* */, &args.parentWindow);
	nfdresult_t result = NFD_PickFolderU8_With(&outPath, &args);
	if (result == NFD_OKAY)
	{
		filename = outPath;
		flog("picker_folder: '%s' selected\n", filename.string().c_str());
		NFD_FreePathU8(outPath);
	}
	else if (result == NFD_CANCEL)
	{
		flog("picker_folder: selection cancelled\n");
	}
	else 
	{
		flog("picker_folder: ERROR\n");
	}

	NFD_Quit();

	return filename;

}
@inflex
Copy link
Author

inflex commented Apr 25, 2025

I trimmed the function right down as far as I can and I still have the same issue. Obviously this variant isn't very functional at all but it still gives me the same issue with the dialog runModal failing still.

nfdresult_t NFD_OpenDialogN_With_Impl(nfdversion_t version,
      nfdnchar_t** outPath,
      const nfdopendialognargs_t* args) {

   NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

   nfdresult_t result = NFD_CANCEL;
   NSOpenPanel* dialog = [NSOpenPanel openPanel];
   if ([dialog runModal] == NSModalResponseOK) {
      result = NFD_OKAY;
   }

   return result;
}

@inflex
Copy link
Author

inflex commented Apr 25, 2025

This is the output from ChatGPT when trying to diagnose the situation -- seems that Sequoia indeed has changed the game;

Thanks for confirming — since this happens during a file picker (like NSOpenPanel or NSSavePanel), the most likely cause is that something (either your app or a system helper/view service) is trying to modify NSUserDefaults with an invalid domain — specifically, an empty or nil string.

Here’s how to approach debugging and resolving this:

🚨 What’s likely happening

macOS Sequoia uses sandboxed helper processes (via ViewBridge) to show open/save panels.

One of these helpers (either yours or a system one) is trying to set user defaults using setObject:forKey:inDomain: with an invalid domain.

This used to silently fail or be ignored in previous macOS versions but now throws a hard exception in Sequoia.

🔍 Possible causes

You (or a library you use) may be customizing the NSOpenPanel or NSSavePanel and accidentally triggering this.

You're installing/accessing something in the panel delegate that manipulates NSUserDefaults using an invalid domain.

You use a third-party framework (e.g. for theming, file handling, or sandboxing) that hooks into file panels and does this.

@btzy
Copy link
Owner

btzy commented Apr 25, 2025

Thanks for the report. This looks somewhat bad if it's making NFDe unusable for all users on macOS Sequoia.

If you have access to a machine running Sequoia, do you mind checking if the example programs function correctly on it? (You can do a quick test by downloading the prebuilt binaries from the CI at https://github.com/btzy/nativefiledialog-extended/actions/runs/13874562190. There are three macOS build artefacts there, but I think just testing the two of them that are labelled as "Static" should be sufficient.) This should help us quickly figure out if this is an NFD problem or something else.

@inflex
Copy link
Author

inflex commented Apr 26, 2025

Can confirm that I've tested the open_cpp_cpp test (and test_sdl2) and it works on Sequoia; as such the problem/issue lays elsewhere ( something clobbering the NSUserDefaults domain I suppose ).

I'll report back what I can find as I suspect this issue may afflict some others.

@inflex
Copy link
Author

inflex commented Apr 27, 2025

Reporting back here in case anyone else suffers this misfortune.

Be sure to populate/add the MACOSX_BUNDLE_GUI_IDENTIFIER attribute for the target properties, as this is the true issue.

       set_target_properties(project_name PROPERTIES
          MACOSX_BUNDLE TRUE
          MACOSX_BUNDLE_GUI_IDENTIFIER "org.domain.yourdetails"
      )

@inflex inflex closed this as completed Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants