Posts

Post not yet marked as solved
2 Replies
107 Views
As an exercise in learning Swift, I rewrote a toy C++ command line tool in Swift. After switching to an UnsafeRawBufferPointer in a critical part of the code, the Release build of the Swift version was a little faster than the Release build of the C++ version. But the Debug build took around 700 times as long. I expect a Debug build to be somewhat slower, but by that much? Here's the critical part of the code, a function that gets called many thousands of times. The two string parameters are always 5-letter words in plain ASCII (it's related to Wordle). By the way, if I change the loop ranges from 0..<5 to [0,1,2,3,4], then it runs about twice as fast in Debug, but twice as slow in Release. func Score( trial: String, target: String ) -> Int { var score = 0 withUnsafeBytes(of: trial.utf8) { rawTrial in withUnsafeBytes(of: target.utf8) { rawTarget in for i in 0..<5 { let trial_i = rawTrial[i]; if trial_i == rawTarget[i] // strong hit { score += kStrongScore } else // check for weak hit { for j in 0..<5 { if j != i { let target_j = rawTarget[j]; if (trial_i == target_j) && (rawTrial[j] != target_j) { score += kWeakScore break } } } } } } } return score }
Posted
by JWWalker.
Last updated
.
Post not yet marked as solved
9 Replies
2.1k Views
I'm getting occasional crashes, which have not happened while running under a debugger and I haven't figured out how to reproduce. I wonder if anyone can help me glean more information from a crash report. Here's the main part. This particular report if from macOS 14.2 beta, but I've also seen it from 14.1.1. Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000018 Exception Codes: 0x0000000000000001, 0x0000000000000018 VM Region Info: 0x18 is not in any region. Bytes before following region: 140723250839528 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL UNUSED SPACE AT START ---> mapped file 7ffcaf60c000-7ffcd7f48000 [649.2M] r-x/r-x SM=COW ...t_id=b7394f27 Error Formulating Crash Report: PC register does not match crashing frame (0x0 vs 0x1022A3630) Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 <translation info unavailable> 0x1022a3630 ??? 1 libsystem_platform.dylib 0x7ff819d0b393 _sigtramp + 51 2 AppKit 0x7ff81d3549a6 -[NSControl _setWindow:] + 59 3 AppKit 0x7ff81d413c19 -[NSSegmentedControl _setWindow:] + 42 4 AppKit 0x7ff81defd3be __21-[NSView _setWindow:]_block_invoke.391 + 324 5 AppKit 0x7ff81d33a62c -[NSView _setWindow:] + 1886 6 AppKit 0x7ff81defd3be __21-[NSView _setWindow:]_block_invoke.391 + 324 7 AppKit 0x7ff81d33a62c -[NSView _setWindow:] + 1886 8 AppKit 0x7ff81d572d08 -[NSWindow dealloc] + 922 9 MyApp 0x1011b6b81 -[JWWindow dealloc] (in MyApp) (JWWindow.m:37) 10 Foundation 0x7ff81b3d179c _NSKVOPerformWithDeallocatingObservable + 151 11 Foundation 0x7ff81acc6d54 NSKVODeallocate + 150 12 libobjc.A.dylib 0x7ff8199189d7 AutoreleasePoolPage::releaseUntil(objc_object**) + 169 13 libobjc.A.dylib 0x7ff819915cf0 objc_autoreleasePoolPop + 235 14 CoreFoundation 0x7ff819d794a1 _CFAutoreleasePoolPop + 22 15 Foundation 0x7ff81ac869ea -[NSAutoreleasePool drain] + 133 16 AppKit 0x7ff81d315694 -[NSApplication run] + 653 17 AppKit 0x7ff81d2e9662 NSApplicationMain + 816 18 MyApp 0x100ef5034 start (in MyApp) + 52 I can see that it involves deallocating a window as part of draining an autorelease pool, but does the presence of _NSKVOPerformWithDeallocatingObservable mean that KVO is involved somehow? And does the note "PC register does not match crashing frame" tell me anything?
Posted
by JWWalker.
Last updated
.
Post marked as solved
2 Replies
177 Views
I have a repeating timer installed like this: _cmdTimer = [NSTimer timerWithTimeInterval: 0.5 target: self selector: @selector(timedTask:) userInfo: nil repeats: YES]; [NSRunLoop.mainRunLoop addTimer: _cmdTimer forMode: NSModalPanelRunLoopMode]; [NSRunLoop.mainRunLoop addTimer: _cmdTimer forMode: NSDefaultRunLoopMode]; The first time the timer fires, it opens a modal dialog. But then the timer does not fire again until the dialog is closed. I don't get that, since I scheduled the timer in NSModalPanelRunLoopMode. To verify that the dialog was running in that mode, just before opening the dialog I said [self performSelector: @selector(testMe) withObject: nil afterDelay: 0.7 inModes: @[NSModalPanelRunLoopMode] ]; and the testMe method did get executed while the dialog was open.
Posted
by JWWalker.
Last updated
.
Post marked as solved
1 Replies
192 Views
Recently, when I open a document in my app, it just adds a blank line to the Open Recent submenu. Attempting to select that line produces an error alert saying "The document “(null)” could not be opened. The file doesn’t exist." However, the document does appear in the global Recent Items menu. I tried rebooting. I'm not subclassing NSDocumentController or doing anything weird about opening files. Ideas? P.S. I tried logging in to a different account, and tried changing the bundle ID. Neither helped.
Posted
by JWWalker.
Last updated
.
Post marked as solved
1 Replies
339 Views
I have a shell script that turns a framework into a plain dylib and updates some dependent library paths using install_name_tool. It works, but if the framework was signed, I get warnings like: install_name_tool: warning: changes being made to the file will invalidate the code signature in: [redacted].dylib (for architecture x86_64) I thought I could get rid of the warning by adding codesign --remove-signature dylib-path to the script before using install_name_tool, but then I get errors like install_name_tool: fatal error: file not in an order that can be processed (link edit information does not fill the __LINKEDIT segment): [redacted].dylib (for architecture x86_64) Is there a way to fix this?
Posted
by JWWalker.
Last updated
.
Post not yet marked as solved
2 Replies
363 Views
I have a view (custom subclass of NSView) that overrides mouseDown: and mouseUp:. If I double-click the view, I expect to see a sequence of events: mouseDown with clickCount == 1 mouseUp with clickCount == 1 mouseDown with clickCount == 2 mouseUp with clickCount == 2 Usually, that's what happens. But occasionally, the second or both mouse up events don't arrive. That's a problem, because it's my understanding that if you want to handle a double-click, you should be looking for the second mouse up. I am certain that the mouse location is always within the bounds of the view. What could cause this? (Testing on macOS 13.6.4.) Added: I use a subclass of NSApplication, and override nextEventMatchingMask:untilDate:inMode:dequeue: and sendEvent:. The overrides usually just call through to the superclass method. Logging mouse events from these methods, I see that in the problematic cases, the mouse up events are received from the queue, but never sent.
Posted
by JWWalker.
Last updated
.
Post not yet marked as solved
0 Replies
264 Views
I want to be able to simulate mouse clicks, moves, and drags within my own app. I can do that using CGEventPost, but that requires accessibility permission, which seems silly to require when I'm not trying to control another app. An alternative is to create mouse NSEvents and use -[NSApplication postEvent:atStart:]. By that approach, I am able to click a button and watch it highlight and unhighlight, but the mouse cursor never moves and the pressedMouseButtons class property of NSEvent never changes. Is there a better way to simulate mouse events without requiring accessibility permission?
Posted
by JWWalker.
Last updated
.
Post not yet marked as solved
0 Replies
422 Views
I replied to this thread a couple of hours ago, but the recent post list, sorted by Last Update, does not show it, and my watch list shows an update date based on a previous reply.
Posted
by JWWalker.
Last updated
.
Post not yet marked as solved
5 Replies
502 Views
If I use -[NSView dataWithPDFInsideRect:] to create a PDF from an NSTextView, I get a single-page PDF with stuff past the bottom cut off. What do I need to do to get pagination to happen? Would embedding the NSTextView in an NSScrollView help?
Posted
by JWWalker.
Last updated
.
Post not yet marked as solved
3 Replies
444 Views
Why is it that I can open a symbolic link, but can't read it? I am aware that I can get the contents of a symlink file using the readlink function, but still, it seems like this ought to work. Here's example code: #include <iostream> #include <unistd.h> #include <fcntl.h> int main(int argc, const char * argv[]) { // Make sure there is not already a file where we will create the link unlink( "/tmp/ReadSymLink-test" ); // Create a symlink int result = symlink( "../usr", "/tmp/ReadSymLink-test"); int err; if (result == 0) { std::cout << "created file /tmp/ReadSymLink-test\n"; } else { err = errno; std::cerr << "symlink failed with error " << err << "\n"; return 1; } // Open it for reading int fd = open( "/tmp/ReadSymLink-test", O_RDONLY | O_SYMLINK ); if (fd < 0) { err = errno; std::cerr << "open failed with error " << err << "\n"; return 2; } std::cout << "open succeeded\n"; // and read it char buffer[200]; ssize_t bytesRead = read( fd, buffer, sizeof(buffer) ); if (bytesRead < 0) { err = errno; std::cerr << "read failed with error " << err << "\n"; return 2; } else { buffer[ bytesRead ] = '\0'; std::cout << "read of symlink result: " << buffer << "\n"; } return 0; } The result, running under Sonoma 14.2 (beta) is created file /tmp/ReadSymLink-test open succeeded read failed with error 1
Posted
by JWWalker.
Last updated
.
Post not yet marked as solved
8 Replies
559 Views
When I'm running my Mac app in the Xcode debugger, and it launches a helper app, the helper crashes with a dyld error. This does not happen if I am not debugging. Termination Reason: Namespace DYLD, Code 1 Library missing Library not loaded: @rpath/Cal3D.framework/Versions/A/Cal3D Referenced from: <3C1A67BA-5545-31A2-86C5-77104B0194FE> /Volumes/VOLUME/*/SBEngineLib4.framework/Versions/A/SBEngineLib4 The frameworks SBEngineLib4.framework and Cal3D.framework exist in the main app. The helper app does not contain any frameworks, but does contain dylib versions of those frameworks, which I suppose is confusing things somehow.
Posted
by JWWalker.
Last updated
.
Post marked as solved
2 Replies
482 Views
I'm trying to download a small data file using NSURLSession, but the completion handler is never called (where "never" means I waited long after the specified timeout). NSURLSessionConfiguration* config = NSURLSessionConfiguration.ephemeralSessionConfiguration; config.timeoutIntervalForResource = 120.0; config.timeoutIntervalForRequest = 120.0; NSURLSession* session = [NSURLSession sessionWithConfiguration: config]; [session dataTaskWithURL: inURL completionHandler: ^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { ... }]; I'm trying to update some old code that used the deprecated NSURLConnection class, and am using the same URL, so I know that the URL is good.
Posted
by JWWalker.
Last updated
.
Post not yet marked as solved
0 Replies
400 Views
I just noticed that +[CIPlugIn loadAllPlugIns] has been deprecated since 10.15 (OK, I'm a little slow), along with all the other CIPlugIn methods except for loadNonExecutablePlugIns. I don't see any documentation about what I'm supposed to do instead. What's the deal?
Posted
by JWWalker.
Last updated
.