[bug] 0.66.0 战斗中识别技能CD(YoloSharp/ONNX DirectML 推理)时 AccessViolationException,进程无任何日志闪退
提交确认 / Checklist
- 我已经搜索过现有 issue,确认这不是重复问题 / I have searched existing issues and confirmed this is not a duplicate
- 我已阅读过文档,确认文档的内容无法解决我的问题 / I have read the documentation and confirmed it does not solve my problem
- 我愿意为了解决这个问题尽自己所能 / I am willing to do my part to help resolve this issue
系统环境
Windows 10 22H2 (19045) x64 .NET Desktop Runtime 8.0.15(CoreCLR 8.0.1525.16413) NVIDIA GeForce RTX 2060(驱动 31.0.15.3640) BGI 日志中 ONNX 初始化:provider "Dml,Cpu",InferenceDevice=Gpu
BetterGI 版本号
0.66.0
问题描述
更新 0.66.0 后,运行涉及战斗的任务时进程两次无任何报错直接消失,日志文件戛然而止, 没有任何 [ERR]/[FTL] 记录,也没有异常堆栈输出到 BGI 日志。 两次崩溃分别发生在:
- 05:56 左右,一条龙的"自动秘境"任务中,战斗策略刚进入"2. 执行战斗策略"约 2 秒后;
- 06:43 左右,执行 JS 锄地脚本(狗粮路线)的战斗过程中,此前连续两条 ConditionEvaluator "迪希雅" 战技cd未更新 警告。 通过 Windows 事件查看器(应用程序日志,.NET Runtime 事件 ID 1026)确认进程是因 未处理的 System.AccessViolationException(访问违例,原生内存损坏)被终止, 且两次的调用链完全一致,都位于战斗脚本检测 E 技能 CD 的推理链路上: CombatCommand.TryTriggerESkillCdCheck → ESkillCdTracker.TriggerECheck → Avatar.AfterUseSkill → Avatar.IsESkillReadyByClassify → YoloSharp YoloPredictor.Predict/Classify → ONNX Runtime 原生层(DirectML) 补充信息:
- 0.65.0 及更早版本在相同负载、相同推理后端(Dml,Gpu)下连续多日运行从未出现崩溃; 0.66.0 于 9/27 安装,9/28 当天即两次崩溃(间隔约 47 分钟)。
- 第二次崩溃堆栈位于 YoloSharp 的 SessionRunnerService.RunWithFixedOutput(MemoryTensor)内部, 连 onnxruntime 托管包装层都未进入,疑似此前一次推理已损坏原生堆,后续调用随机爆在任意位置。
期望结果
- 战斗过程中该推理路径不应发生访问违例,进程不应闪退;
- 若为偶发的原生层异常,期望至少能被隔离/记录到 BGI 日志,而不是整个进程静默消失;
- 若 DirectML 后端存在问题,希望能提供开关(关闭该 CD 识别检测或强制该模型走 CPU 推理)作为规避手段。
复现步骤
无法 100% 手动复现,当天两次均为运行中随机出现,但两次崩溃点同链路:
- 使用 0.66.0,推理设备为 GPU(日志显示 provider "Dml,Cpu",InferenceDevice=Gpu);
- 运行含战斗的任务(一次是一条龙含"自动秘境",战斗脚本"那维莱特秘境"; 另一次是 JS 锄地脚本,队伍含迪希雅);
- 战斗过程中战斗脚本触发 E 技能 CD 检测进行头像/技能识别推理时,进程随机闪退;
- BGI 日志在闪退前最后一行之后无任何输出(两次分别运行了约 2 分钟、42 分钟)。
日志与附件
- 当天完整日志
better-genshin-impact20260928.log
两次闪退前日志最后几行如下:
崩溃一(一条龙 - 自动秘境): [05:56:33.829] [INF] 匹配到战斗脚本:"那维莱特秘境" [05:56:34.064] [INF] 自动秘境:"1. 走到钥匙处启动" [05:56:35.063] [INF] 检测到交互键 [05:56:35.120] [INF] 自动秘境:"2. 执行战斗策略" (此后无任何输出,进程消失)
崩溃二(JS 锄地脚本战斗中): [06:42:56.476] [INF] 交互或拾取:"游医" [06:43:01.273] [WRN] [BetterGenshinImpact.GameTask.AutoFight.Script.ConditionEvaluator] "迪希雅" 战技cd未更新 [06:43:03.408] [WRN] [BetterGenshinImpact.GameTask.AutoFight.Script.ConditionEvaluator] "迪希雅" 战技cd未更新 (此后无任何输出,进程消失)
ONNX 初始化(每个会话相同): [ONNX]启用的provider:"Dml,Cpu",初始化参数: InferenceDevice=Gpu, OptimizedModel=False, CudaDeviceId=0, DmlDeviceId=0, EmbedTensorRtCache=True, EnableTensorRtCache=True, CpuOcr=False
- Windows 事件查看器 - .NET Runtime(事件 ID 1026)两条崩溃记录的完整堆栈:
── 2026-09-28 05:56:37 ──
Application: BetterGI.exe
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException: Attempted to read or write protected memory.
Stack:
at Microsoft.ML.OnnxRuntime.InferenceSession.RunWithBinding(RunOptions, OrtIoBinding)
at Compunet.YoloSharp.Services.SessionRunnerService.RunWithFixedOutput(MemoryTensor1<Single>) at Compunet.YoloSharp.Services.SessionRunnerService.PreprocessAndRun(Image1, PredictorTimer ByRef)
at Compunet.YoloSharp.YoloPredictor.Predict[[System.__Canon]](Image1<Rgb24>, YoloConfiguration) at Compunet.YoloSharp.YoloPredictorExtensions.Classify(YoloPredictor, Image1, YoloConfiguration)
at BetterGenshinImpact.GameTask.AutoFight.Model.Avatar.IsESkillReadyByClassify(ImageRegion, Boolean)
at BetterGenshinImpact.GameTask.AutoFight.Model.Avatar.ReadSkillCdFromScreenshot(ImageRegion, Boolean)
at BetterGenshinImpact.GameTask.AutoFight.Model.Avatar.AfterUseSkill(ImageRegion)
at BetterGenshinImpact.GameTask.AutoFight.Script.CombatCommand.b__20_0()
at BetterGenshinImpact.GameTask.AutoFight.Script.ESkillCdTracker.b__6_0()
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(...)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
── 2026-09-28 06:43:04 ──
Application: BetterGI.exe
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException: Attempted to read or write protected memory.
Stack:
at Compunet.YoloSharp.Services.SessionRunnerService.RunWithFixedOutput(MemoryTensor1<Single>) at Compunet.YoloSharp.Services.SessionRunnerService.PreprocessAndRun(Image1, PredictorTimer ByRef)
at Compunet.YoloSharp.YoloPredictor.Predict[[System.__Canon]](Image`1, YoloConfiguration)
at BetterGenshinImpact.GameTask.AutoFight.Model.Avatar.IsESkillReadyByClassify(ImageRegion, Boolean)
at BetterGenshinImpact.GameTask.AutoFight.Model.Avatar.AfterUseSkill(ImageRegion)
at BetterGenshinImpact.GameTask.AutoFight.Script.CombatCommand.b__20_0()
at BetterGenshinImpact.GameTask.AutoFight.Script.ESkillCdTracker.b__6_0()
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(...)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
Source: babalae/better-genshin-impact