[p5.js 2.0+ Bug Report]: textAlign() with an invalid horizontal value draws nothing in 2D but falls back to LEFT in WEBGL
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 85/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript
调研方向
阅读 src/core/p5.Renderer2D.js(第942-956行)中的水平对齐 switch,并添加 default: adjustedX = x; 以匹配 Renderer3D 的 fallback。在 typography 测试套件中为 textAlign 使用一个无效的水平值添加单元测试。当 2D 画布在 LEFT 绘制文本且新测试通过时完成。
由索引模型根据 Issue 内容生成。
描述
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- WebGPU
- p5.strands
- Build process
- Unit testing
- Internationalization
- Friendly errors
- Other (specify if possible)
p5.js version
2.3.4 (Web Editor). Source checked on main at 51eefe3d0, and the relevant code is the same.
Web browser and version
156.0.8078.48 (Official Build) (arm64)
Operating system
MacOS GoldenGate
Steps to reproduce this
Steps to reproduce this
textAlign() saves any string as the horizontal alignment. When the value isn't LEFT, CENTER or RIGHT, the 2D and WEBGL renderers handle it differently. An easy way to hit this is textAlign(TOP), which passes a vertical constant into the horizontal slot.
| 2D | WEBGL | |
|---|---|---|
textAlign(LEFT) (control) |
text drawn at left | text drawn at left |
textAlign(TOP) |
nothing drawn | text drawn at left |
Controls (textAlign(LEFT)), 2D then WEBGL:
textAlign(TOP), 2D then WEBGL:
With FES on, both renderers show the same warning:
🌸 p5.js says: Expected constant (please refer to documentation for allowed values) at the first parameter, but received top in textAlign().
So the user is warned, but what happens next depends on the renderer.
With p5.disableFriendlyErrors = true, the 2D sketch draws nothing and the p5 console is empty. The only message is the browser's CanvasTextAlign warning in DevTools, which doesn't point to textAlign():
Sketch:
// p5.disableFriendlyErrors = true; // uncomment for the FES-off run
let font;
async function setup() {
createCanvas(200, 100); // or createCanvas(200, 100, WEBGL)
font = await loadFont('Arial.ttf');
// translate(-width / 2, -height / 2); // WEBGL only
background(220);
textFont(font);
textSize(20);
textAlign(TOP); // LEFT for the control
text('hello', 20, 50);
}
Why they differ (from reading the source). Both renderers work out the x position with a switch (textAlign):
src/core/p5.Renderer3D.js:1891–1909hasdefault: adjustedX = x, so an unknown value falls back to LEFT.src/core/p5.Renderer2D.js:942–956has nodefault:. That leavesadjustedXasundefined, and it gets passed tofillText()as the x coordinate, so nothing is drawn.- The shared helper
_xAlignOffset(src/type/textCore.js:2103) also hasdefault: return 0, so the 2D renderer is the only one without a fallback.
Possible fix: add default: adjustedX = x; to the 2D switch so both renderers fall back to LEFT, plus a unit test.
I'd like to fix this myself if approved.
- 主要语言
- JavaScript
- 星标
- 24.3k
- 派生
- 3.9k
- 平均合并
- 3 天 19 小时
- 30 天内合并 PR
- 48
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
processing/p5.js 的其他 Issue
-
[p5.js 2.0+ Bug Report]: Incorrect isDone assignment in MediaElement.onended() example可能已有人在做 @BhumitSahani 于 4 天前认领。 未关闭Area:DOM p5.js 2.0+
难度 1/5 1 小时以内 新手友好度 86/100
processing/p5.js#9339 · 2 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
-
[p5.js 2.0+ Bug Report]: Mismatched map() Reference Example可能已有人在做 @j-xsen 于 4 天前认领。 未关闭Area:Math Documentation p5.js 2.0+
难度 1/5 1 小时以内 新手友好度 87/100
processing/p5.js#9329 · 2 条评论 ·
维护者通常 2 天内回复
-
Area:Core p5.js 2.0+
难度 2/5 1-3 小时 新手友好度 66/100
processing/p5.js#9319 · 1 条评论 ·
维护者通常 2 天内回复
-
Area:WebGL p5.js 2.0+ p5.strands
难度 2/5 1-3 小时 新手友好度 68/100
processing/p5.js#9317 · 4 条评论 ·
维护者通常 2 天内回复
-
[p5.js 2.0+ Bug Report]: createRadio().disable(false) does not re-enable radio inputs可能已有人在做 @aryanb1906 于 4 天前认领。 未关闭Area:DOM Good First Issue p5.js 2.0+
难度 2/5 1-3 小时 新手友好度 76/100
processing/p5.js#9316 · 5 条评论 · 1 个 reaction ·
维护者通常 2 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
-
agent bug
难度 1/5 1 小时以内 新手友好度 88/100
-
bug 🐛
难度 2/5 1-3 小时 新手友好度 78/100
comunica/comunica#1925 · 1 条评论 ·
维护者通常 1 天内回复
-
factory-active task-identify-harness-labels-done task-identify-issue-type-done
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复