Skip to content
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

parsePattern crash #637

Closed
kamil3 opened this issue Nov 20, 2019 · 7 comments
Closed

parsePattern crash #637

kamil3 opened this issue Nov 20, 2019 · 7 comments
Assignees
Milestone

Comments

@kamil3
Copy link

kamil3 commented Nov 20, 2019

Fatal error: Unexpectedly found nil while unwrapping an Optional value: file (...)/Macaw-master/Source/svg/SVGParser.swift, line 402
I'm testing Macaw Example and I changed a default tiger image to my own SVG image. My SVG image contains pattern attribute. Both in a web browser and finder it renders fine.

Shortened contents of SVG:
<?xml version="1.0" encoding="UTF-8"?> <svg width="1600px" height="1600px" viewBox="0 0 1600 1600" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <!-- Generator: Sketch 54.1 (76490) - https://sketchapp.com --> <title>Test</title> <desc>Created with Sketch.</desc> <defs> <pattern id="pattern-1" patternUnits="objectBoundingBox" x="0%" width="100%" height="100%"> <use xlink:href="#image-2"></use> </pattern> <image id="image-2" width="1600" height="1600" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAB9AAAAfQCAIAAAAVWlMuAAAABGdBTUEAALGOfPtRkwAAAAlwSFlzAAAN1wAADdcBQiibeAAAQABJREF(...) </defs> <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g id="Artboard" transform="translate(-14698.000000, -14063.000000)" fill="url(#pattern-1)" stroke="#979797"> <g id="Test" transform="translate(14698.000000, 14063.000000)"> <path d="M0.5,0.5 L0.5,1599.5 L1599.5,1599.5 L1599.5,0.5 L0.5,0.5 Z M74.5,74.5 L1525.5,74.5 L1525.5,1525.5 L74.5,1525.5 L74.5,74.5 Z" id="Combined-Shape"></path> </g> </g> </g> </svg>

@amarunko
Copy link
Contributor

Hi, @kamil3, can you attach the correct SVG file? This file is actually broken.

@weitzel926
Copy link

@amarunko - I don't have a sample svg I can post but there are certainly crashes in here. For example, in SVGParser parsePattern, this code executes:

if let shape = try parseNode(pattern.children.first!) as? Shape {
contentNode = shape
}

If that let fails then contentNode never gets set. Then it gets unwrapped with the crash operator on the return and blows up.

return UserSpacePattern(content: contentNode!, bounds: bounds, userSpace: userSpace, contentUserSpace: contentUserSpace)

(using 0.9.5)

@amarunko
Copy link
Contributor

Sorry, but without example for debugging - it is very hard to find the reason, the place is known - it is better than nothing of course, but parsing depends on many styles, parent attributes, etc.

@weitzel926
Copy link

@amarunko
colorado.svg.zip

The file in this zip shows the problem in my test code.

@amarunko
Copy link
Contributor

Thank you very much, I will look deeper soon

Sent with GitHawk

@amarunko
Copy link
Contributor

Fixed here

@ystrot ystrot added this to the 0.9.6 milestone Nov 28, 2019
@ystrot
Copy link
Member

ystrot commented Nov 28, 2019

Merged PR which should fix this issue, so closing it.

@ystrot ystrot closed this as completed Nov 28, 2019
@ystrot ystrot modified the milestones: 0.9.6, 0.9.7 Apr 10, 2020
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

No branches or pull requests

4 participants