Comments (13)
found it! Will push a PR fix for this later today. 2000000 not a problem on either renderer now
from pixijs.
hey there! this was a conscious choice as we figured by limiting the complexity of the graphics - we could simplify the logic under the hood .
It would be good to understand the use case. Thanks!
from pixijs.
Hi Mat and thank you for caring.
Usecase: Many dashed/dotted lines.
I do so be using moveTo
/lineTo
pairs often on a Graphics
for each gap/dash.
It worked fine with V7,
What jumps to my mind is that - reading the error message - 5000 moveTo
/lineTo
pairs require a 800.000.000 bytes buffer??
That is 160.000 bytes/pair. Sounds pretty much?
Second, just doing lineTo
(without moveTo
) can easily do 4.900.000 lines before buffer limits are reached.
In the end, it should look like this, rendered with v7:
This is the code:
import { Graphics, PointData } from "pixi.js";
function distance(p1: PointData, p2: PointData) {
return Math.hypot(p2.x - p1.x, p2.y - p1.y);
}
export type DashGap = { dash: number, gap: number };
// V8 8.0.0-rc.11 moveTo/lineTo browser crash
// high numbers (>3000) of moveTo/lineTo crash the browser
// https://github.com/pixijs/pixijs/issues/10265
export class DashedLine {
startX = 0;
startY = 0;
dashGapIndex = 0;
remaingDash = 0;
remaingGap = 0;
readonly #dashGaps: DashGap[];
constructor(private graphics: Graphics, dashGaps: DashGap[], scale: number) {
this.#dashGaps = dashGaps.map(dashGap => ({dash: dashGap.dash / scale, gap: dashGap.gap / scale}));
}
public moveTo(x: number, y: number) {
this.dashGapIndex = 0;
this.remaingDash = 0;
this.remaingGap = 0;
this.startX = x;
this.startY = y;
}
public lineTo(x: number, y: number) {
this.paint({x: this.startX, y: this.startY}, {x, y})
this.startX = x;
this.startY = y;
}
public paint(p1: PointData, p2: PointData) {
const g = this.graphics;
const len = distance(p1, p2);
const norm = { x: (p2.x - p1.x) / len, y: (p2.y - p1.y) / len };
// start with the remaining gap
let progress = this.remaingGap;
// reduce remaining gap if line segment is very short and cannot complete the gap
if (progress > len) {
this.remaingGap = Math.max(0, this.remaingGap - len);
}
while (progress < len) {
this.remaingGap = 0;
const {dash, gap} = this.#dashGaps[this.dashGapIndex];
g.moveTo(p1.x + progress * norm.x, p1.y + progress * norm.y);
// set progress to the end of the dash
progress += this.remaingDash || dash;
if (progress > len) {
// we cannot paint the dash completely
this.remaingDash = progress - len;
// do not paint beyond to end point
progress = len;
g.lineTo(p1.x + progress * norm.x, p1.y + progress * norm.y);
} else {
// switch dashgap only if the latest dash is complete
this.dashGapIndex = ++this.dashGapIndex % this.#dashGaps.length;
g.lineTo(p1.x + progress * norm.x, p1.y + progress * norm.y);
// dash fully painted
this.remaingDash = 0;
// set progress to end of gap
progress += gap;
// can we complete the gap with this line segement?
if (progress > len) {
this.remaingGap = progress - len;
}
}
}
}
}
from pixijs.
this is super helpful - thanks for sharing this line drawing code - will have a play and get back to you! the buffer sizes do sound a bit high!
from pixijs.
The line drawing code finds a condensed, isolated form in the playground https://www.pixiplayground.com/#/edit/4M3bzWyTVU0_BFZLzD95I
from pixijs.
Hey @joergplewe - seems like a webGPU limitation rather than a pixi one. Using the WebGL renderer will provide a work around for now why we investigate at least!
https://www.pixiplayground.com/#/edit/4M3bzWyTVU0_BFZLzD95I
from pixijs.
Yeah thanks, that slightly shifts the limit from <2900 to <8200.
I did a crosscheck with a v7 version of the same, where the limit is well >2.000.000:
https://www.pixiplayground.com/#/edit/7pqux6HZlhr2M-wOaxhUw
(did you know that one cannot choose v7 version in the playground any more? I recycled on old one :) )
from pixijs.
looks like it WebGPU has a hard limit on buffers size. Figured most people would not need that much complexity in a single geometry!
perhaps i got that on wrong! For now, would this be enough to render your lines? (like as each full line is an individual graphics?)
thanks!
from pixijs.
oh, actually i think i can fix webGL easily.. will report back
from pixijs.
I'm optimistic finding a workaround.
Just ... why does that moderate set of moveTo
/lineTo
pairs require that huge buffersizes? While e.g. lineTo
alone does not?
from pixijs.
i think there might be something wrong in how the buffer size is calculated for large graphics. Just verifying now
from pixijs.
Yeah, you are the man! :)
from pixijs.
haha! thanks :) - appreciate the help getting to the bottom of this one! Open source at its finest!
from pixijs.
Related Issues (20)
- Virus detected when I try to download PixiJS HOT 2
- Bug: [v8] Missing information on Migration guide for v8 or in the Blog post of v8 HOT 4
- Bug: [v8] Rollup export build error after upgrade to v8 - working on v7 HOT 4
- Bug: WEBGL: INVALID_VALUE: shaderSource: string not ASCII (Older chrome version) HOT 6
- Bug: BaseRenderTexture no longer exists in v8 HOT 1
- Bug: Graphics with only strokes that don't have a closePath, but an event is fired where a closePath would have been
- Bug: BindGroup setResource called with null HOT 2
- Bug: Reloading an Animated Sprite breaks rendering HOT 3
- Bug: Some link in https://pixijs.download/v8.0.1/docs/rendering.AutoDetectOptions.html not working HOT 1
- Bug: HTMLText does not render
- Bug: v8 migration guide missing key info about several changes from v7 HOT 2
- Bug: Current environment does not allow unsafe-eval, please use @pixi/unsafe-eval module to enable support HOT 3
- Bug: [v8 regression] initial text rendering much slower than in v7 HOT 3
- Bug: the demo links can't open
- Feature Request: caching bitmap fonts in client? HOT 11
- Bug: Cannot read property 'getExtension' of undefined
- Bug: [v8] `text.style.fill === null` when `TextStyle` is reused instead of `TextStyleOptions` HOT 2
- Bug: [v8] BpuBufferSystem.onBufferDestroy contains null gpuBuffer when destroying via react hook HOT 6
- Bug: [v8 regression] pointerevents can drastically cut performance HOT 2
- Is there a way to simulate 3d projection/rotation in Pixi v8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pixijs.