Skip to content

一堆BUG #18

Description

@bfxh

🔴 BUG #1 [HIGH] dllmain.cpp - Loop 线程不是后台线程,导致游戏无法正常关闭

文件 : CSharpLoaderDll/dllmain.cpp (间接关联) / CSharpManager/CSharpModManager.cs

问题代码 :

问题 :

  1. IsBackground = true 被注释掉,Loop 线程是前台线程
  2. while(true) 无限循环没有退出条件
  3. 当玩家关闭游戏时,这个前台线程阻止整个进程退出,导致:
    • 游戏窗口关闭后,进程 b1-Win64-Shipping.exe 仍在后台运行
    • Steam 认为游戏还在运行,无法再次启动
    • 需要任务管理器手动结束进程
      修复建议 :

🔴 BUG #2 [HIGH] CSharpModManager.cs - Mod 加载失败时 LoadingModName 不重置

文件 : CSharpManager/CSharpModManager.cs

问题代码 :

问题 :

  1. File.Exists 检查失败时 continue ,但 LoadingModName 保持为上一个 mod 的名称
  2. catch 异常时也没有重置
  3. 导致后续 mod 的 AssemblyResolve 事件会错误地解析到上一个失败 mod 的目录下查找依赖 DLL
  4. 可能加载错误版本的依赖 DLL,导致游戏崩溃
    修复建议 :

🔴 BUG #3 [HIGH] InputManager.cs - IsProgramFocused 每次都 Sleep 1 秒

文件 : CSharpManager/InputManager.cs

问题代码 :

问题 :

  • Update() 每 10ms 被调用一次
  • 当窗口句柄未找到时, 每次 IsProgramFocused() 都会 Sleep 1000ms
  • 这导致游戏启动阶段、切换窗口时、窗口丢失时, 程序几乎卡死
  • 严重影响游戏帧率(C# 层卡顿传递到 Mono 运行时)
    修复建议 :

🟡 BUG #4 [MEDIUM] dllmain.cpp - JIT 签名检测日志消息写反

文件 : CSharpLoaderDll/dllmain.cpp

问题代码 :

问题 : 当 == 0 (未找到)时打印 "found",严重 误导调试诊断 。虽然不影响功能( else 分支才执行补丁),但会让开发者误判。

修复 :

🟡 BUG #5 [MEDIUM] memory.cpp - swap_virtual_table 内存泄漏

文件 : CSharpLoaderDll/memory.cpp

问题代码 :

问题 :

  1. 每次调用都 new 分配新内存
  2. 旧的 vtable 没有 delete[] ,造成 内存泄漏
  3. 频繁的 vtable 交换会导致内存持续增长
  4. DeInit 时无法恢复原始 vtable

🟡 BUG #6 [LOW] Ini.cs - endWithCRLF 数组越界

文件 : CSharpManager/Ini.cs

问题代码 :

问题 : 当 sb.Length < 2 时(比如空文件), sb[sb.Length - 2] 会抛出 IndexOutOfRangeException 。

修复 :

🟡 BUG #7 [MEDIUM] InputManager.cs - HandleKeys 缺少括号导致逻辑不明确

文件 : CSharpManager/InputManager.cs

问题代码 :

问题 : 缺少括号,依赖 C# 的 && > || 运算符优先级。虽然当前功能可能正确,但:

  1. 代码可读性差
  2. 容易在后续修改中引入 bug
  3. 当 item.Key == Key.None 时 KeyUtils.IsKeyDown(0) 行为未定义
    修复 : 添加括号明确表达意图:
if ((item.Modifiers == modifiers && KeyUtils.IsKeyDown(item.Key)) ||
    (CurrentGamePadButton != GamePadButton.None && item.
    GamePadButton != GamePadButton.None && CurrentGamePadButton.
    HasFlag(item.GamePadButton)))

📊 汇总

严重程度 文件 问题 影响 1 HIGH CSharpModManager.cs Loop 线程非后台 游戏无法正常关闭,进程残留 2 HIGH CSharpModManager.cs LoadingModName 不重置 加载错误依赖 DLL,可能导致崩溃 3 HIGH InputManager.cs IsProgramFocused Sleep 1000ms 启动阶段严重卡顿 4 MEDIUM dllmain.cpp 日志消息写反 误导调试 5 MEDIUM memory.cpp vtable 内存泄漏 长时间运行内存增长 6 LOW Ini.cs 数组越界 空文件时崩溃 7 MEDIUM InputManager.cs 括号缺失 可读性/潜在逻辑错误

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions