-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0. #9937
Comments
This happens because some stroke gets converted to a pattern based gradients and with some calculations we are going below 1 to 0. This can be fixed probably, is an extreme edge case it tho. having a smaller SVG that trigger the issue would help |
This is fixed in 6.0 already, backports are low priority. _applyPatternForTransformedGradient(
ctx: CanvasRenderingContext2D,
filler: TFiller
) {
const dims = this._limitCacheSize(this._getCacheCanvasDimensions()),
pCanvas = createCanvasElement(),
retinaScaling = this.getCanvasRetinaScaling(),
width = dims.x / this.scaleX / retinaScaling,
height = dims.y / this.scaleY / retinaScaling;
// in case width and height are less than 1px, we have to round up.
// since the pattern is no-repeat, this is fine
pCanvas.width = Math.ceil(width); // <--- this is the fix
pCanvas.height = Math.ceil(height); // <--- this is the fix
const pCtx = pCanvas.getContext('2d');
if (!pCtx) {
return;
} You can open a PR to apply the same fix to 5.x |
Check if this build fix the issue: #9965 |
Hello @asturur , |
@asturur |
thanks |
CheckList
Version
5.3.0
In What environments are you experiencing the problem?
No response
Node Version (if applicable)
None
Link To Reproduction
https://jsfiddle.net/na7xo3gf/
Steps To Reproduce
Expected Behavior
When this SVG is resized to a very small height, it should resize without any issues at this height.
Actual Behavior
However, the SVG completely disappears from the canvas and the following error is thrown.
Note that this doesn't happen with other SVGs. There's something about this one that crashes fabric.
Error Message & Stack Trace
The text was updated successfully, but these errors were encountered: