Skip to content

fix(canvas2d): return TextMetrics for empty measureText - #150

Merged
triniwiz merged 1 commit into
NativeScript:masterfrom
LorenzGit:neonleap/canvas-empty-measuretext
Sep 10, 2026
Merged

fix(canvas2d): return TextMetrics for empty measureText#150
triniwiz merged 1 commit into
NativeScript:masterfrom
LorenzGit:neonleap/canvas-empty-measuretext

Conversation

@LorenzGit

Copy link
Copy Markdown
Contributor

Problem

Pixi 8 CanvasTextSystem._drawLetterSpacing always calls context.measureText(remainder).width. When the remainder is "", NativeScript Canvas returned without constructing a TextMetrics object, so .width threw and any new Text(...) crashed on iOS/tvOS.

Change

Remove the if (text_utf8_len == 0) return; guard. Empty strings go through the existing text engine/cache and return a metrics instance with width 0, matching browsers.

Test plan

  • measureText("") is an object with width === 0
  • Pixi Text with default letter-spacing no longer throws on NativeScript Canvas
  • Verified on Apple TV simulator with Pixi 8.5.2 (NEONLEAP)

Does not include the concentric-radial Skia experiment; two-point conical already fades correctly on this stack.

Pixi 8 CanvasTextSystem reads .width on empty remainder strings when
letter-spacing is present. Returning without a metrics object crashes
any Pixi Text on NativeScript Canvas.
@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: f4289e3e-0112-470d-ab6d-74c038caedae

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@LorenzGit

Copy link
Copy Markdown
Contributor Author

The red AudioContext jobs are not from this diff.

  • iOS: NSCOpusDecoder.mm:7:10: fatal error: 'opusfile.h' file not found
  • Android: CMake add_subdirectory for missing third_party/oboe

The last Canvas Native run on master (merge of #149, run 34359199107) failed the same AudioContext jobs (and Canvas iOS/Android). This PR does not touch packages/audio-context.

The relevant job for this change is Build Native / Canvas iOS + visionOS.

@triniwiz
triniwiz merged commit 6f69749 into NativeScript:master Sep 10, 2026
4 of 9 checks passed
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.

2 participants