Skip to content

Handle zero C2S meter in UGC export - #7

Open
dudehacker wants to merge 1 commit into
MuNET-OSS:masterfrom
dudehacker:fix/c2s-zero-meter-timing
Open

dudehacker wants to merge 1 commit into
MuNET-OSS:masterfrom
dudehacker:fix/c2s-zero-meter-timing

Conversation

@dudehacker

@dudehacker dudehacker commented Oct 7, 2026 •

Copy link
Copy Markdown

fix crashes due to timing issue

example chart:
2503_03.zip

Review in cubic

Sourcery 总结

使 UGC 导出能够稳健处理无效拍号,同时保留有效的节拍和音符时序。

错误修复:

  • 防止当谱面包含分子为零或其他无效拍号值时,UGC 导出崩溃以及时序映射错误。

增强功能:

  • 忽略无效拍号,并在没有剩余有效拍号时提供默认节拍映射,从而保留后续音符的时序。

测试:

  • 增加对分子为零和分母为零拍号的覆盖测试,包括警报生成和后续音符时序。
Original summary in English

Summary by Sourcery

Make UGC export robust against invalid time signatures while preserving valid beat and note timing.

Bug Fixes:

  • Prevent UGC export crashes and incorrect timing mappings when charts contain zero or otherwise invalid time-signature values.

Enhancements:

  • Preserve later note timing by ignoring invalid meters and providing a default beat mapping when no valid meters remain.

Tests:

  • Add coverage for zero-numerator and zero-denominator meters, including alert generation and subsequent note timing.

@sourcery-ai

sourcery-ai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

审查者指南

导出器现在可以通过在节拍图构建期间发出警告并忽略无效的零值拍号,避免因时序相关问题导致的崩溃;必要时会回退到有效的默认拍号,并增加回归测试以确认后续音符的时序仍然正确。

具备容错能力的 UGC 节拍图导出时序图

sequenceDiagram
    participant Serialize
    participant FillUgcBeats
    participant Alerts
    participant BeatMap
    participant Notes

    Serialize->>FillUgcBeats: FillUgcBeats(metList)
    loop each meter
        alt Numerator <= 0 or Denominator <= 0
            FillUgcBeats->>Alerts: Add(Alert.Warning)
            FillUgcBeats-->>FillUgcBeats: Ignore invalid meter
        else Valid meter
            FillUgcBeats->>BeatMap: Add valid beat entry
        end
    end
    opt No valid beat entries
        FillUgcBeats->>BeatMap: Add default 4/4 entry
    end
    FillUgcBeats-->>Serialize: Return beat map
    Serialize->>Notes: Serialize note timing using beat map
Loading

文件级变更

变更 详细信息 文件
使 UGC 节拍图生成能够适应无效拍号,包括值为零的 C2S 分子。
  • 跳过分子或分母为非正数的拍号,并在该拍号对应的时间点发出警告提醒。
  • 当不再存在有效拍号时,提供一个默认的 4/4 节拍条目,同时保留后续有效拍号的映射。
generator/chu/UgcGenerator.cs
增加针对无效拍号导出和音符时序保留的回归测试。
  • 构建一个在有效拍号前后都包含分子为零的拍号的谱面。
  • 验证仅产生一条警告、忽略无效节拍输出、保留有效节拍映射,并且后续音符会以预期的 UGC 位置进行序列化。
tests/chu/UgcTimeTests.cs

提示和命令

与 Sourcery 交互

  • 触发新的审查: 在拉取请求中评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 回复审查评论,请 Sourcery 根据该评论创建 issue。你也可以回复审查评论并使用 @sourcery-ai issue,从该评论创建 issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在拉取请求中评论 @sourcery-ai title,以随时生成或重新生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任意位置写入 @sourcery-ai summary,即可在指定位置随时生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary,以随时生成或重新生成摘要。
  • 生成审查者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时生成或重新生成审查者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,以解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,此命令会很有用。
  • 忽略所有 Sourcery 审查: 在拉取请求中评论 @sourcery-ai dismiss,以忽略所有现有的 Sourcery 审查。如果你想通过新的审查重新开始,这个命令尤其有用——别忘了评论 @sourcery-ai review 以触发新的审查!

自定义使用体验

访问你的控制面板以:

  • 启用或禁用审查功能,例如 Sourcery 生成的拉取请求摘要、审查者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

The exporter now avoids timing-related crashes from invalid zero-valued meters by warning and ignoring them during beat-map construction, falls back to a valid default meter when necessary, and adds regression coverage confirming later note timing remains correct.

Sequence diagram for resilient UGC beat-map export

sequenceDiagram
    participant Serialize
    participant FillUgcBeats
    participant Alerts
    participant BeatMap
    participant Notes

    Serialize->>FillUgcBeats: FillUgcBeats(metList)
    loop each meter
        alt Numerator <= 0 or Denominator <= 0
            FillUgcBeats->>Alerts: Add(Alert.Warning)
            FillUgcBeats-->>FillUgcBeats: Ignore invalid meter
        else Valid meter
            FillUgcBeats->>BeatMap: Add valid beat entry
        end
    end
    opt No valid beat entries
        FillUgcBeats->>BeatMap: Add default 4/4 entry
    end
    FillUgcBeats-->>Serialize: Return beat map
    Serialize->>Notes: Serialize note timing using beat map
Loading

File-Level Changes

Change Details Files
Make UGC beat-map generation resilient to invalid meters, including zero C2S numerators.
  • Skip meters with non-positive numerators or denominators and emit a warning alert at the meter time.
  • Provide a default 4/4 beat entry when no valid meters remain, while preserving subsequent valid meter mappings.
generator/chu/UgcGenerator.cs
Add regression coverage for invalid-meter export and note timing preservation.
  • Build a chart containing zero numerator meters before and after a valid meter.
  • Verify one warning is produced, invalid beat output is omitted, the valid beat mapping remains, and a later note serializes at the expected UGC position.
tests/chu/UgcTimeTests.cs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你好——我已经审阅了你的更改,看起来很棒!

Sourcery 评估

已批准。


Sourcery 对开源项目免费——如果你喜欢我们的审阅结果,请考虑分享它们 ✨
Original comment in English

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="generator/chu/UgcGenerator.cs">

<violation number="1" location="generator/chu/UgcGenerator.cs:97">
P3: 新增的告警文案是硬编码中文,没有走 Locale 资源。README「多语言 (i18n)」一节要求新增/修改 key 必须维护 zh、zh-Hant、en 三种一级语言,同文件 `AirColor` 中的告警也使用了 `Locale.C2SUnsupportedAirColor`(i18n/Locale.resx、Locale.zh.resx、Locale.zh-Hant.resx 等均有对应 key)。建议改为 `Locale` 资源 key 并补三种语言的翻译。</violation>

<violation number="2" location="generator/chu/UgcGenerator.cs:123">
P3: 新增的「全部拍号无效/为空时兜底补 (0,4,4)」分支没有任何测试覆盖。现有测试 `UgcGenerator_IgnoresZeroNumeratorMeterAndKeepsMappingLaterNotes` 的 metList 是 [4/4@0, 1/4@1, 0/4@3],0/4 出现在中间,跳过它之后 `_ugcBeats` 仍有 2 项,不会走到这个 count==0 的分支。本 PR 修复的核心崩溃场景(C2S 起始小节就是 0/4 拍号、或整张谱没有有效 MET)正是靠这一行兜底,建议补一个 metList 为空或全部为无效拍号的用例,断言不崩溃且输出仅含 `@BEAT 0 4 4`。</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

{
if (met.Numerator <= 0 || met.Denominator <= 0)
{
alerts.Add(new Alert(Alert.LEVEL.Warning,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: 新增的告警文案是硬编码中文,没有走 Locale 资源。README「多语言 (i18n)」一节要求新增/修改 key 必须维护 zh、zh-Hant、en 三种一级语言,同文件 AirColor 中的告警也使用了 Locale.C2SUnsupportedAirColor(i18n/Locale.resx、Locale.zh.resx、Locale.zh-Hant.resx 等均有对应 key)。建议改为 Locale 资源 key 并补三种语言的翻译。

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At generator/chu/UgcGenerator.cs, line 97:

<comment>新增的告警文案是硬编码中文,没有走 Locale 资源。README「多语言 (i18n)」一节要求新增/修改 key 必须维护 zh、zh-Hant、en 三种一级语言,同文件 `AirColor` 中的告警也使用了 `Locale.C2SUnsupportedAirColor`(i18n/Locale.resx、Locale.zh.resx、Locale.zh-Hant.resx 等均有对应 key)。建议改为 `Locale` 资源 key 并补三种语言的翻译。</comment>

<file context>
@@ -86,12 +86,19 @@ void Dfs(ChuNote n)
         {
+            if (met.Numerator <= 0 || met.Denominator <= 0)
+            {
+                alerts.Add(new Alert(Alert.LEVEL.Warning,
+                    $"UGC Generator忽略无效拍号: {met.Numerator}/{met.Denominator}", met.Time));
+                continue;
</file context>

_ugcBeats.Add((ugcBar, met.Numerator, met.Denominator));
}

if (_ugcBeats.Count == 0) _ugcBeats.Add((0, 4, 4));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: 新增的「全部拍号无效/为空时兜底补 (0,4,4)」分支没有任何测试覆盖。现有测试 UgcGenerator_IgnoresZeroNumeratorMeterAndKeepsMappingLaterNotes 的 metList 是 [4/4@0, 1/4@1, 0/4@3],0/4 出现在中间,跳过它之后 _ugcBeats 仍有 2 项,不会走到这个 count==0 的分支。本 PR 修复的核心崩溃场景(C2S 起始小节就是 0/4 拍号、或整张谱没有有效 MET)正是靠这一行兜底,建议补一个 metList 为空或全部为无效拍号的用例,断言不崩溃且输出仅含 @BEAT 0 4 4。

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At generator/chu/UgcGenerator.cs, line 123:

<comment>新增的「全部拍号无效/为空时兜底补 (0,4,4)」分支没有任何测试覆盖。现有测试 `UgcGenerator_IgnoresZeroNumeratorMeterAndKeepsMappingLaterNotes` 的 metList 是 [4/4@0, 1/4@1, 0/4@3],0/4 出现在中间,跳过它之后 `_ugcBeats` 仍有 2 项,不会走到这个 count==0 的分支。本 PR 修复的核心崩溃场景(C2S 起始小节就是 0/4 拍号、或整张谱没有有效 MET)正是靠这一行兜底,建议补一个 metList 为空或全部为无效拍号的用例,断言不崩溃且输出仅含 `@BEAT 0 4 4`。</comment>

<file context>
@@ -112,13 +119,15 @@ private void FillUgcBeats(List<MET> metList)
             _ugcBeats.Add((ugcBar, met.Numerator, met.Denominator));
         }
+
+        if (_ugcBeats.Count == 0) _ugcBeats.Add((0, 4, 4));
     }
 
</file context>

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant