搭载M2芯片的macOS Ventura上JavaFX应用启动断言失败求助
问题描述
在搭载M2芯片的macOS Ventura系统上启动JavaFX应用时出现断言失败,应用使用Gradle 7.3.1、JDK 17.0.7和JavaFX SDK 21构建,启动时抛出以下错误:
2023-09-26 21:06:14.194 java[42409:778654418] *** Assertion failure in -[_NSTrackingAreaAKViewHelper removeTrackingRect:], _NSTrackingAreaAKManager.m:1585 2023-09-26 21:06:14.196 java[42409:778654418] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '0x0 is an invalid NSTrackingRectTag. Common possible reasons for this are: 1. already removed this trackingRectTag, 2. Truncated the NSTrackingRectTag to 32bit at some point.' *** First throw call stack: ( 0 CoreFoundation 0x00007ff813fa5cd3 __exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007ff813af610a objc_exception_throw + 48 2 Foundation 0x00007ff814d82fb0 -[NSCalendarDate initWithCoder:] + 0 3 AppKit 0x00007ff81763e562 -[_NSTrackingAreaAKViewHelper removeTrackingRect:] + 190 4 libglass.dylib 0x00000001099f068a -[GlassViewDelegate setFrameSize:] + 362 5 libglass.dylib 0x00000001099f5fb8 -[GlassView3D setFrameSize:] + 88 6 AppKit 0x00007ff816fca3a1 -[NSView setFrame:] + 347 7 libglass.dylib 0x00000001099f6011 -[GlassView3D setFrame:] + 65 8 AppKit 0x00007ff816fdb0f9 -[NSView resizeWithOldSuperviewSize:] + 694 9 AppKit 0x00007ff816fdaa2a -[NSView resizeSubviewsWithOldSize:] + 488 10 AppKit 0x00007ff816fba206 -[NSView setFrameSize:] + 1446 11 AppKit 0x00007ff816fca3a1 -[NSView setFrame:] + 347 12 AppKit 0x00007ff816fdb0f9 -[NSView resizeWithOldSuperviewSize:] + 694 13 AppKit 0x00007ff816fdaa2a -[NSView resizeSubviewsWithOldSize:] + 488 14 AppKit 0x00007ff816fba206 -[NSView setFrameSize:] + 1446 15 AppKit 0x00007ff816fd8e2d -[NSThemeFrame setFrameSize:] + 482 16 AppKit 0x00007ff816fd84f4 -[NSWindow _oldPlaceWindow:fromServer:] + 813 17 AppKit 0x00007ff816fd6ae5 -[NSWindow _setFrameCommon:display:fromServer:] + 1656 18 libglass.dylib 0x00000001099e7c24 -[GlassWindow(Java) _setFlipFrame:display:animate:] + 228 19 libglass.dylib 0x00000001099e776f -[GlassWindow(Java) _setWindowFrameWithRect:withDisplay:withAnimate:] + 255 20 libglass.dylib 0x00000001099e79d9 -[GlassWindow(Java) _setBounds:y:xSet:ySet:w:h:cw:ch:] + 601 21 libglass.dylib 0x0000000109a01353 Java_com_sun_glass_ui_mac_MacWindow__1setBounds2 + 435 22 ??? 0x0000000116ebf365 0x0 + 4679529317 ) libc++abi: terminating with uncaught exception of type NSException /Applications/InBetween_j17/Admin/IBAdmin.command: line 3: 42409 Abort trap: 6 ../Libraries/jre/bin/java -Xms1024m -Xmx4096m -Dlog4j.configurationFile=file://"`dirname "$0"`"/log4j2.xml -Djava.security.policy=java.policy -Dprism.order=sw,j2d --module-path "../Libraries/javafx/lib" --add-modules javafx.controls,javafx.fxml -classpath ./*:../Libraries/Core/IBCommon.jar:../Libraries/Core/IBStubs.jar:../Libraries/Core/IBCore.jar:../Libraries/Core/core.jar:../Libraries/lib/* -Xdock:icon=./IBAdmin.app/Contents/Resources/IB_Admin.icns application.IBAdmin
应用在M1芯片或其他Mac设备上运行正常,此前使用JDK 11和JavaFX SDK 11时可正常运行,目前正迁移至Java 17及新版本。
解决方案
1. 调整Prism渲染参数
当前启动参数使用-Dprism.order=sw,j2d强制软件渲染,M2芯片的Metal渲染层对JavaFX的支持更稳定,尝试修改参数:
- 替换为
-Dprism.order=metal,sw,优先使用Metal硬件渲染 - 添加
-Dglass.mac.disableNativeTrackingArea=true,直接禁用Native层的跟踪区域(针对本次NSTrackingRectTag错误的核心修复) - 或尝试
-Dprism.forceGPU=true强制启用GPU加速
2. 确保依赖的架构兼容性
- 确认JDK 17.0.7是arm64架构版本,而非x86_64版本(通过Rosetta运行会导致Native层兼容性问题),运行
java -version查看输出是否包含aarch64/arm64标识 - 确保JavaFX SDK 21是针对arm64的包,避免混用x86版本
3. 修复窗口初始化逻辑
错误触发在窗口Bounds设置阶段,检查代码:
- 避免启动时设置0尺寸或极小尺寸的窗口
- 延迟窗口尺寸调整:在
Application.start()中先调用stage.show(),再执行尺寸设置 - 排查是否存在重复调用窗口尺寸修改的代码,导致多次移除同一TrackingRectTag
4. 升级工具链版本
- 将Gradle升级到8.x稳定版,Gradle 7.3.1对JDK 17和JavaFX 21的支持不够完善,新版本能更好适配现代JavaFX和arm64架构
- 同步升级JavaFX Gradle插件到最新版(如
org.openjfx.javafxplugin:0.1.0及以上)
5. 禁用MacOS特定系统特性
尝试添加以下启动参数绕过Native层冲突:
-Dglass.mac.useScreenMenuBar=false:禁用系统菜单栏集成-Dglass.mac.hideWindowMenuBar=true:隐藏窗口菜单栏
内容的提问来源于stack exchange,提问作者sogytots
相关产品推荐
相关产品推荐

