#1097·makepad

Crash on app termination

Author: gterzianCreated May 27, 2026Updated Jun 11, 2026

Crash log:

Thread 0 Crashed:: main
0   libsystem_kernel.dylib        	       0x18acd25b0 __pthread_kill + 8
1   libsystem_pthread.dylib       	       0x18ad0c888 pthread_kill + 296
2   libsystem_c.dylib             	       0x18ac12808 abort + 124
3   makepad-host                  	       0x105d81b1c _RNvNtNtNtCsg55jX0GwzBC_3std3sys3pal4unix14abort_internal + 12
4   makepad-host                  	       0x105d8189c _RNvNtCsg55jX0GwzBC_3std7process5abort + 12
5   makepad-host                  	       0x105d0e1ac _RNvNtCsg55jX0GwzBC_3std9panicking15panic_with_hook + 796
6   makepad-host                  	       0x105cfaacc _RNCNvNtCsg55jX0GwzBC_3std9panicking13panic_handler0B5_ + 112
7   makepad-host                  	       0x105cf2130 _RINvNtNtCsg55jX0GwzBC_3std3sys9backtrace26___rust_end_short_backtraceNCNvNtB6_9panicking13panic_handler0zEB6_ + 12
8   makepad-host                  	       0x105cfb2d8 _RNvCsfLfy6EI15iL_7___rustc17rust_begin_unwind + 32
9   makepad-host                  	       0x105d82218 _RNvNtCsl8K0bEFm1U0_4core9panicking18panic_nounwind_fmt + 40
10  makepad-host                  	       0x105d82330 _RNvNtCsl8K0bEFm1U0_4core9panicking30panic_null_pointer_dereference + 28
11  makepad-host                  	       0x10575fc00 makepad_platform::os::apple::macos::macos_window::MacosWindow::get_ime_origin::hf204a8602c1abcfa + 436
12  makepad-host                  	       0x105772110 makepad_platform::os::apple::macos::macos_delegates::define_cocoa_view_class::first_rect_for_character_range::h94431b958b811fbb + 556
13  AppKit                        	       0x19000b6e4 -[NSTextInputContext(NSInputContext_WithCompletion) firstRectForCharacterRange:completionHandler:] + 140
14  AppKit                        	       0x190009fe0 -[NSTextInputContext firstRectForCharacterRange:actualRange:] + 228
15  AppKit                        	       0x18fd7f824 -[NSAutoFillHeuristicController _isAbleToHandleAutoFillForTextInputContext:] + 80
16  AppKit                        	       0x18fd7c5d8 -[NSAutoFillHeuristicController showOrHideAutoFillForCurrentTextInputContextIfAppropriate] + 204
17  Foundation                    	       0x18c5ca5e4 __NSFireDelayedPerform + 372
18  CoreFoundation                	       0x18adba290 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 32
19  CoreFoundation                	       0x18adb9f50 __CFRunLoopDoTimer + 980
20  CoreFoundation                	       0x18adb9ac8 __CFRunLoopDoTimers + 280
21  CoreFoundation                	       0x18adaa84c __CFRunLoopRun + 1816
22  CoreFoundation                	       0x18ae68898 _CFRunLoopRunSpecificWithOptions + 532
23  AppKit                        	       0x18fb2928c -[NSPersistentUIManager _waitForPendingChangesToFinish] + 888
24  AppKit                        	       0x18f2d5f20 -[NSPersistentUIManager discardAllPersistentStateAndClose] + 196
25  AppKit                        	       0x18f2875e4 -[NSApplication _pushPersistentStateTerminationGeneration] + 200
26  AppKit                        	       0x18f6e8398 -[NSApplication terminate:] + 528
27  makepad-host                  	       0x10592b784 _$LT$$LP$A$C$$RP$$u20$as$u20$makepad_objc_sys..message..MessageArguments$GT$::invoke::hb40768ecc00cdd28 + 96
28  makepad-host                  	       0x105911350 makepad_objc_sys::message::platform::send_unverified::hf2c00e818f1cbc3b + 152
29  makepad-host                  	       0x105733468 makepad_platform::os::apple::macos::macos_app::MacosApp::do_callback::hdd3c35e2e2997490 + 1440
30  makepad-host                  	       0x10575e1cc makepad_platform::os::apple::macos::macos_window::MacosWindow::do_callback::hf7e9c070bff7b32b + 48
31  makepad-host                  	       0x1057661a4 makepad_platform::os::apple::macos::macos_window::MacosWindow::send_window_closed_event::h92d5c0520855f9c6 + 56
32  makepad-host                  	       0x105777940 makepad_platform::os::apple::macos::macos_delegates::define_macos_window_delegate::window_will_close::h823d88ed4ad8eeb2 + 68
33  CoreFoundation                	       0x18ada2574 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 148
34  CoreFoundation                	       0x18ae0b0c4 ___CFXRegistrationPost_block_invoke + 92
35  CoreFoundation                	       0x18ae0b008 _CFXRegistrationPost + 436
36  CoreFoundation                	       0x18ad8108c _CFXNotificationPost + 740
37  Foundation                    	       0x18cf8a3e0 -[NSNotificationCenter postNotificationName:object:userInfo:] + 88
38  AppKit                        	       0x18fe31688 -[NSWindow _finishClosingWindow] + 304
39  AppKit                        	       0x18f2bf3e8 -[NSWindow _close] + 380
40  AppKit                        	       0x18f2d4920 -[NSWindow __close] + 376
41  AppKit                        	       0x18fbedbb4 -[NSApplication(NSResponder) sendAction:to:from:] + 560
42  AppKit                        	       0x18f82278c -[NSControl sendAction:to:] + 72
43  AppKit                        	       0x18f7abdc8 __26-[NSCell _sendActionFrom:]_block_invoke + 100
44  AppKit                        	       0x18f7abcf0 -[NSCell _sendActionFrom:] + 204
45  AppKit                        	       0x18f771b8c -[NSButtonCell _sendActionFrom:] + 96
46  AppKit                        	       0x18f25d5bc NSControlTrackMouse + 1492
47  AppKit                        	       0x18f7acaac -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 144
48  AppKit                        	       0x18f76fe90 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 232
49  AppKit                        	       0x18fe1c910 -[NSControl(_NSTracking) _mouseDown:] + 612
50  AppKit                        	       0x18fe1c680 -[NSControl(_NSTracking) mouseDown:] + 104
51  AppKit                        	       0x18fedec14 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 3676
52  AppKit                        	       0x18fedba9c -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 492
53  AppKit                        	       0x18fedb52c -[NSWindow(NSEventRouting) sendEvent:] + 372
54  AppKit                        	       0x18fbea558 -[NSApplication(NSEventRouting) sendEvent:] + 1276
55  makepad-host                  	       0x10592b784 _$LT$$LP$A$C$$RP$$u20$as$u20$makepad_objc_sys..message..MessageArguments$GT$::invoke::hb40768ecc00cdd28 + 96
56  makepad-host                  	       0x105911350 makepad_objc_sys::message::platform::send_unverified::hf2c00e818f1cbc3b + 152
57  makepad-host                  	       0x1057352dc makepad_platform::os::apple::macos::macos_app::MacosApp::process_ns_event::hbded30120bb7802a + 1400
58  makepad-host                  	       0x105732a8c makepad_platform::os::apple::macos::macos_app::MacosApp::event_loop::h719d20efb1e483a4 + 3732
59  makepad-host                  	       0x105676818 makepad_platform::os::apple::macos::macos::_$LT$impl$u20$makepad_platform..cx..Cx$GT$::event_loop::hc7d89f56763869e6 + 1748
60  makepad-host                  	       0x10465edf8 makepad_app_host::app::app_main::h502e8ffae9586196 + 984
61  makepad-host                  	       0x1046787fc makepad_app_host::run::h53957541eba7fc1e + 16
62  makepad-host                  	       0x10465120c makepad_host::main::hec33a1e0ec252f9c + 12 (main.rs:2)
63  makepad-host                  	       0x10465135c core::ops::function::FnOnce::call_once::hb78f3e6b6ffe83c7 + 20 (function.rs:250)
64  makepad-host                  	       0x104651390 std::sys::backtrace::__rust_begin_short_backtrace::h8b8f4f6955fffbc1 + 24 (backtrace.rs:166)
65  makepad-host                  	       0x1046512bc std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::hf2ac9e4a3ee8cd80 + 28 (rt.rs:206)
66  makepad-host                  	       0x105d0c9a4 _RNvNtCsg55jX0GwzBC_3std2rt19lang_start_internal + 952
67  makepad-host                  	       0x104651294 std::rt::lang_start::h81449d66bdd93030 + 84 (rt.rs:205)
68  makepad-host                  	       0x104651238 main + 36
69  dyld                          	       0x18a94dd54 start + 7184

Initial AI analysis:

Crash Analysis: makepad-host on macOS
Root Cause
The crash is a null pointer dereference in the IME (Input Method Editor) subsystem, triggered during app termination. The key frames in Thread 0:
10  panic_null_pointer_dereference
11  MacosWindow::get_ime_origin          ← null deref here
12  first_rect_for_character_range       ← called by AppKit
13  NSTextInputContext firstRectForCharacterRange
14  NSAutoFillHeuristicController        ← AutoFill polling for IME rect
What Happened — Step by Step

User clicks the close button (frames 46–53) — AppKit routes a mouse-down through NSButtonCell → NSControl → NSWindow.
Window begins closing (frames 38–41) — _finishClosingWindow fires a NSWindowWillCloseNotification.
Makepad handles windowWillClose (frame 32) and calls send_window_closed_event, which calls back into MacosApp::do_callback (frame 29).
Concurrently, a delayed timer fires (frames 17–21) via NSFireDelayedPerform — this is macOS's NSAutoFillHeuristicController checking whether AutoFill should show for the active text input context.
AutoFill asks for the IME cursor rect by calling firstRectForCharacterRange (frame 13), which delegates into makepad's first_rect_for_character_range callback (frame 12).
That callback calls MacosWindow::get_ime_origin (frame 11), but by this point the window is already being torn down — some internal pointer (likely the MacosWindow struct itself, or a Cx/view reference it holds) has been dropped or nulled, causing the dereference.
Rust's panic_null_pointer_dereference fires (frame 10), which escalates through panic_with_hook → abort → pthread_kill(SIGABRT).

Why It Races
The window-close notification and the AutoFill timer are both handled on the main run loop, but the window teardown inside makepad's Rust layer happens synchronously inside do_callback. The timer fires during that same run loop iteration (note both paths converge from __CFRunLoopRun at frame 21), catching the Rust window state partially destroyed while AppKit still holds a live NSTextInputContext pointing at it.
The Bug in makepad
get_ime_origin dereferences a pointer/reference that is no longer valid after the window close event is dispatched. The function doesn't guard against a "window is closing/closed" state.

Recommended Fixes
1. Guard get_ime_origin against a closed/nil window state
rustfn get_ime_origin(&self) -> Option<DVec2> {
    if self.is_closing {
        return None; // or return a default rect
    }
    // ... existing logic
}
2. Resign first responder before teardown
In send_window_closed_event or the window-will-close handler, explicitly resign the text input context so AppKit stops querying it:
objc// In the Obj-C delegate or via makepad's objc bindings:
[nsView.window makeFirstResponder:nil];
// or
[NSTextInputContext.currentInputContext invalidateCharacterCoordinates];
3. Unregister the Cocoa view as a text input client early
Before the Rust MacosWindow drops its internals, ensure the associated NSView is no longer registered as an NSTextInputClient. This prevents AutoFill/IME from calling back at all.
4. Return a safe fallback rect instead of panicking
Even if the above guards aren't in place, first_rect_for_character_range should never panic — it should return NSZeroRect or a screen-edge rect as a safe fallback when the window state is unavailable.