[p5.js 2.0+ Bug Report]: textAlign() with an invalid horizontal value draws nothing in 2D but falls back to LEFT in WEBGL
Maintainer antworten meist innerhalb von 2 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 85/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- javascript
- Bereich
- computer-graphics
Rechercherichtung
Lies den horizontalen Ausrichtungs-Switch in src/core/p5.Renderer2D.js (Zeilen 942-956) und füge default: adjustedX = x; hinzu, um dem Fallback von Renderer3D zu entsprechen. Füge einen Unit-Test für textAlign mit einem ungültigen horizontalen Wert in der Typography-Suite hinzu. Erledigt, wenn der 2D-Canvas Text bei LEFT zeichnet und der neue Test besteht.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 24.3k
- Forks
- 3.9k
- Ø Merge
- 3 T. 19 Std.
- Gemergte PRs (30 T.)
- 48
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus processing/p5.js
-
[p5.js 2.0+ Bug Report]: Incorrect isDone assignment in MediaElement.onended() exampleEvtl. vergeben @BhumitSahani hat das vor 3 Tagen übernommen. OffenArea:DOM p5.js 2.0+
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 86/100
processing/p5.js#9339 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 2 Tagen
-
[p5.js 2.0+ Bug Report]: Mismatched map() Reference ExampleEvtl. vergeben @j-xsen hat das vor 4 Tagen übernommen. OffenArea:Math Documentation p5.js 2.0+
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 87/100
processing/p5.js#9329 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Area:Core p5.js 2.0+
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
processing/p5.js#9319 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Area:WebGL p5.js 2.0+ p5.strands
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
processing/p5.js#9317 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 2 Tagen
-
[p5.js 2.0+ Bug Report]: createRadio().disable(false) does not re-enable radio inputsEvtl. vergeben @aryanb1906 hat das vor 4 Tagen übernommen. OffenArea:DOM Good First Issue p5.js 2.0+
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
processing/p5.js#9316 · 5 Kommentare · 1 Reaktion ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in processing/p5.js
Ähnliche Issues
-
44-x-y bug :beetle:
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 82/100
electron/electron#55528 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
react/react-native#59699 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
status: needs triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
mastra-ai/mastra#29053 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
[feature] Extra citiesOffenenhancement triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
fjaeckel/seriesoftubes#230 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Maintainer antworten meist innerhalb von 1 Tag