Skip to content

macOS: Repeated crash in NSScrollerImp drawKnobSlotInRect on background thread #2425

@joschiv1977

Description

@joschiv1977

Environment

  • OS: macOS 15.7.4 (24G517), ARM64
  • Mac Model: Mac16,10
  • HeidiSQL Version: 12.15.1.1 (macOS .app bundle)
  • MySQL Server: 8.4.8

Description

HeidiSQL crashes repeatedly on macOS when a scrollbar is being rendered on a background thread. I experienced 5 crashes within 4 minutes today (2026-03-09, between 09:58 and 10:02).

The root cause appears to be a UI operation (scrollbar drawing) happening on a non-main thread, which violates macOS/AppKit's requirement that all UI work must occur on the main thread.

Crash Flow

  1. NSScrollerImp drawKnobSlotInRect:highlight:alpha: is called on a background thread (Thread 9)
  2. CUIRenderer::Draw() fails
  3. FPC_BREAK_ERROR triggers a Free Pascal runtime error
  4. The exception handler (MAIN$_$TMAINFORM_$__$$_APPLICATIONEXCEPTION) tries to show a modal error dialog via ShowModal — still on the background thread
  5. NSWindow initWithContentRect:styleMask:backing:defer: throws an NSException because window creation is not allowed off the main thread
  6. This leads to objc_exception_throwabort()EXC_BREAKPOINT (SIGTRAP)

Crashing Thread Stack Trace (Thread 9)

__abort
abort
abort_message
demangling_terminate_handler()
_objc_terminate()
std::__terminate(void (*)())
__cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*)
__cxa_throw
objc_exception_throw
-[NSException raise]
-[NSWindow _initContent:styleMask:backing:defer:contentView:]
-[NSWindow initWithContentRect:styleMask:backing:defer:]
COCOAWSFORMS$_$TCOCOAWSCUSTOMFORM_$__$$_CREATEHANDLE$TWINCONTROL$TCREATEPARAMS$$QWORD
CONTROLS$_$TWINCONTROL_$__$$_CREATEWND
FORMS$_$TSCROLLINGWINCONTROL_$__$$_CREATEWND
FORMS$_$TCUSTOMFORM_$__$$_CREATEWND
FORMS$_$TFORM_$__$$_CREATEWND
CONTROLS$_$TWINCONTROL_$__$$_CREATEHANDLE
CONTROLS$_$TWINCONTROL_$__$$_HANDLENEEDED
CONTROLS$_$TWINCONTROL_$_DOALLAUTOSIZE_$$_CHECKHANDLEALLOCATED$TWINCONTROL$$BOOLEAN
CONTROLS$_$TWINCONTROL_$__$$_DOALLAUTOSIZE
CONTROLS$_$TCONTROL_$__$$_ENABLEAUTOSIZING
CONTROLS$_$TCONTROL_$__$$_SETVISIBLE$BOOLEAN
FORMS$_$TCUSTOMFORM_$__$$_SETVISIBLE$BOOLEAN
FORMS$_$TCUSTOMFORM_$__$$_SHOW
FORMS$_$TCUSTOMFORM_$__$$_SHOWMODAL$$LONGINT
MAIN$_$TMAINFORM_$__$$_APPLICATIONEXCEPTION$TOBJECT$EXCEPTION
FORMS$_$TAPPLICATION_$__$$_HANDLEEXCEPTION$TOBJECT
FORMS_$$_EXCEPTIONOCCURRED$TOBJECT$POINTER$LONGINT$PPOINTER
SYSTEM_$$_DOUNHANDLEDEXCEPTION
FPC_RAISEEXCEPTION
SYSUTILS_$$_RUNERRORTOEXCEPT$LONGINT$POINTER$POINTER
FPC_BREAK_ERROR
CUIRenderer::Draw(CGRect, CGContext*, __CFDictionary const*, __CFDictionary const**)
CUIDraw
-[NSCompositeAppearance _callCoreUIWithBlock:options:requireBezelTintColor:]
-[NSAppearance _drawInRect:context:options:]
-[NSScrollerImp drawKnobSlotInRect:highlight:alpha:]
-[TCocoaScrollBar drawKnobSlotInRect:highlight:]
-[NSScroller drawRect:]
_NSViewDrawRect
-[NSView _recursive:displayRectIgnoringOpacity:inContext:stopAtLayerBackedViews:]
-[NSView(NSLayerKitGlue) _drawViewBackingLayer:inContext:drawingHandler:]
-[NSViewBackingLayer drawInContext:]
-[NSViewBackingLayer display]
CA::Layer::display_if_needed(CA::Transaction*)
CA::Context::commit_transaction(CA::Transaction*, double, double*)
CA::Transaction::commit()
CA::Transaction::release_thread(void*)
_pthread_tsd_cleanup
_pthread_exit
pthread_exit
CTHREADS_$$_CENDTHREAD$LONGWORD
SYSTEM_$$_ENDTHREAD$LONGWORD
CLASSES_$$_THREADFUNC$POINTER$$INT64
CTHREADS_$$_THREADMAIN$POINTER$$POINTER
_pthread_start
thread_start

Exception Details

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000018d024a94
Termination:     Trace/BPT trap: 5
ASI:             libsystem_c.dylib - abort() called

Suggested Fix

  1. Ensure all scrollbar rendering (TCocoaScrollBar drawKnobSlotInRect:) is dispatched to the main thread
  2. The exception handler (ApplicationExceptionShowModal) should check if it's on the main thread before attempting to create a window, or use TThread.Synchronize / dispatch_async(dispatch_get_main_queue(), ...) to show the dialog on the main thread

Crash Reports

All 5 crash reports (.ips files) are available if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugDefective behaviour in HeidiSQLmacosAffects the macOS app bundle

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions