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

App crash when rendering SVG #1740

Open
antondalgren opened this issue Apr 8, 2022 · 10 comments · May be fixed by #2307
Open

App crash when rendering SVG #1740

antondalgren opened this issue Apr 8, 2022 · 10 comments · May be fixed by #2307
Labels

Comments

@antondalgren
Copy link

Bug

Rendering the following SVG causes app to crash, it is reproducible by rendering it in a clean project with the latest versions.

It is throwing errors on style="transform:translate3d", style="transform:translate" and fill="859e9d" that is missing a # to indicate that the value is hex. I have not managed to understand what causes the app crash, but I think it might be related to text animation.

SVG
<svg width="290" height="500" viewBox="0 0 290 500" xmlns="http://www.w3.org/2000/svg" xmlns:xlink='http://www.w3.org/1999/xlink'>
  <defs>
    <filter id="f1">
      <feImage result="p0" xlink:href="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0nMjkwJyBoZWlnaHQ9JzUwMCcgdmlld0JveD0nMCAwIDI5MCA1MDAnIHhtbG5zPSdodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2Zyc+PHJlY3Qgd2lkdGg9JzI5MHB4JyBoZWlnaHQ9JzUwMHB4JyBmaWxsPScjODU5ZTlkJy8+PC9zdmc+" />
      <feImage result="p1" xlink:href="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0nMjkwJyBoZWlnaHQ9JzUwMCcgdmlld0JveD0nMCAwIDI5MCA1MDAnIHhtbG5zPSdodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2Zyc+PGNpcmNsZSBjeD0nMjQzJyBjeT0nMjk4JyByPScxMjBweCcgZmlsbD0nI2M3Nzg0MScvPjwvc3ZnPg==" />
      <feImage result="p2" xlink:href="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0nMjkwJyBoZWlnaHQ9JzUwMCcgdmlld0JveD0nMCAwIDI5MCA1MDAnIHhtbG5zPSdodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2Zyc+PGNpcmNsZSBjeD0nMjM2JyBjeT0nMjY0JyByPScxMjBweCcgZmlsbD0nIzVhOTFiOCcvPjwvc3ZnPg==" />
      <feImage result="p3" xlink:href="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0nMjkwJyBoZWlnaHQ9JzUwMCcgdmlld0JveD0nMCAwIDI5MCA1MDAnIHhtbG5zPSdodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2Zyc+PGNpcmNsZSBjeD0nMTU5JyBjeT0nMTY3JyByPScxMDBweCcgZmlsbD0nIzBjZDVhYicvPjwvc3ZnPg==" />
      <feBlend mode="overlay" in="p0" in2="p1" />
      <feBlend mode="exclusion" in2="p2" />
      <feBlend mode="overlay" in2="p3" result="blendOut" />
      <feGaussianBlur in="blendOut" stdDeviation="42" />
    </filter>
    <clipPath id="corners">
      <rect width="290" height="500" rx="42" ry="42" />
    </clipPath>
    <path id="text-path-a" d="M40 12 H250 A28 28 0 0 1 278 40 V460 A28 28 0 0 1 250 488 H40 A28 28 0 0 1 12 460 V40 A28 28 0 0 1 40 12 z" />
    <path id="minimap" d="M234 444C234 457.949 242.21 463 253 463" />
    <filter id="top-region-blur">
      <feGaussianBlur in="SourceGraphic" stdDeviation="24" />
    </filter>
    <linearGradient id="grad-up" x1="1" x2="0" y1="1" y2="0">
      <stop offset="0.0" stop-color="white" stop-opacity="1" />
      <stop offset=".9" stop-color="white" stop-opacity="0" />
    </linearGradient>
    <linearGradient id="grad-down" x1="0" x2="1" y1="0" y2="1">
      <stop offset="0.0" stop-color="white" stop-opacity="1" />
      <stop offset="0.9" stop-color="white" stop-opacity="0" />
    </linearGradient>
    <mask id="fade-up" maskContentUnits="objectBoundingBox">
      <rect width="1" height="1" fill="url(#grad-up)" />
    </mask>
    <mask id="fade-down" maskContentUnits="objectBoundingBox">
      <rect width="1" height="1" fill="url(#grad-down)" />
    </mask>
    <mask id="none" maskContentUnits="objectBoundingBox">
      <rect width="1" height="1" fill="white" />
    </mask>
    <linearGradient id="grad-symbol">
      <stop offset="0.7" stop-color="white" stop-opacity="1" />
      <stop offset=".95" stop-color="white" stop-opacity="0" />
    </linearGradient>
    <mask id="fade-symbol" maskContentUnits="userSpaceOnUse">
      <rect width="290px" height="200px" fill="url(#grad-symbol)" />
    </mask>
  </defs>
  <g clip-path="url(#corners)">
    <rect fill="859e9d" x="0px" y="0px" width="290px" height="500px" />
    <rect style="filter: url(#f1)" x="0px" y="0px" width="290px" height="500px" />
    <g style="filter:url(#top-region-blur); transform:scale(1.5); transform-origin:center top;">
      <rect fill="none" x="0px" y="0px" width="290px" height="500px" />
      <ellipse cx="50%" cy="0px" rx="180px" ry="120px" fill="#000" opacity="0.85" />
    </g>
    <rect x="0" y="0" width="290" height="500" rx="42" ry="42" fill="rgba(0,0,0,0)" stroke="rgba(255,255,255,0.2)" />
  </g>
  <text text-rendering="optimizeSpeed">
    <textPath startOffset="-100%" fill="white" font-family="'Courier New', monospace" font-size="10px" xlink:href="#text-path-a">
      0xc778417e063141139fce010982780140aa0cd5ab b" WETH
      <animate additive="sum" attributeName="startOffset" from="0%" to="100%" begin="0s" dur="30s" repeatCount="indefinite" />
    </textPath>
    <textPath startOffset="0%" fill="white" font-family="'Courier New', monospace" font-size="10px" xlink:href="#text-path-a">
      0xc778417e063141139fce010982780140aa0cd5ab b" WETH
      <animate additive="sum" attributeName="startOffset" from="0%" to="100%" begin="0s" dur="30s" repeatCount="indefinite" />
    </textPath>
    <textPath startOffset="50%" fill="white" font-family="'Courier New', monospace" font-size="10px" xlink:href="#text-path-a">
      0x859e9d8a4edadfedb5a2ff311243af80f85a91b8 b" cETH
      <animate additive="sum" attributeName="startOffset" from="0%" to="100%" begin="0s" dur="30s" repeatCount="indefinite" />
    </textPath>
    <textPath startOffset="-50%" fill="white" font-family="'Courier New', monospace" font-size="10px" xlink:href="#text-path-a">
      0x859e9d8a4edadfedb5a2ff311243af80f85a91b8 b" cETH
      <animate additive="sum" attributeName="startOffset" from="0%" to="100%" begin="0s" dur="30s" repeatCount="indefinite" />
    </textPath>
  </text>
  <g mask="url(#fade-symbol)">
    <rect fill="none" x="0px" y="0px" width="290px" height="200px" />
    <text y="70px" x="32px" fill="white" font-family="'Courier New', monospace" font-weight="200" font-size="36px">cETH/WETH</text>
    <text y="115px" x="32px" fill="white" font-family="'Courier New', monospace" font-weight="200" font-size="36px">0.05%</text>
  </g>
  <rect x="16" y="16" width="258" height="468" rx="26" ry="26" fill="rgba(0,0,0,0)" stroke="rgba(255,255,255,0.2)" />
  <g mask="url(#fade-down)" style="transform:translate(72px,189px)">
    <rect x="-16px" y="-16px" width="180px" height="180px" fill="none" />
    <path d="M1 1C1 89 57.5 145 145 145" stroke="rgba(0,0,0,0.3)" stroke-width="32px" fill="none" stroke-linecap="round" />
  </g>
  <g mask="url(#fade-down)" style="transform:translate(72px,189px)">
    <rect x="-16px" y="-16px" width="180px" height="180px" fill="none" />
    <path d="M1 1C1 89 57.5 145 145 145" stroke="rgba(255,255,255,1)" fill="none" stroke-linecap="round" />
  </g>
  <circle cx="73px" cy="190px" r="4px" fill="white" />
  <circle cx="73px" cy="190px" r="24px" fill="none" stroke="white" />
  <g style="transform:translate(29px, 384px)">
    <rect width="84px" height="26px" rx="8px" ry="8px" fill="rgba(0,0,0,0.6)" />
    <text x="12px" y="17px" font-family="'Courier New', monospace" font-size="12px" fill="white">
      <tspan fill="rgba(255,255,255,0.6)">ID:</tspan>
      9361
    </text>
  </g>
  <g style="transform:translate(29px, 414px)">
    <rect width="140px" height="26px" rx="8px" ry="8px" fill="rgba(0,0,0,0.6)" />
    <text x="12px" y="17px" font-family="'Courier New', monospace" font-size="12px" fill="white">
      <tspan fill="rgba(255,255,255,0.6)">Min Tick:</tspan>
      229320
    </text>
  </g>
  <g style="transform:translate(29px, 444px)">
    <rect width="140px" height="26px" rx="8px" ry="8px" fill="rgba(0,0,0,0.6)" />
    <text x="12px" y="17px" font-family="'Courier New', monospace" font-size="12px" fill="white">
      <tspan fill="rgba(255,255,255,0.6)">Max Tick:</tspan>
      231320
    </text>
  </g>
  <g style="transform:translate(226px, 433px)">
    <rect width="36px" height="36px" rx="8px" ry="8px" fill="none" stroke="rgba(255,255,255,0.2)" />
    <path stroke-linecap="round" d="M8 9C8.00004 22.9494 16.2099 28 27 28" fill="none" stroke="white" />
    <circle style="transform:translate3d(24px, 27px, 0px)" cx="0px" cy="0px" r="4px" fill="white" />
  </g>
</svg>

Environment info

Run react-native info in your terminal and copy the results here. Also, include the precise version number of this library that you are using in the project

React native info output:

 System:
    OS: macOS 12.3.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 586.08 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.2/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.11.3 - /opt/homebrew/lib/ruby/gems/3.0.0/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK: Not Found
  IDEs:
    Android Studio: 2020.3 AI-203.7717.56.2031.7935034
    Xcode: 13.3/13E113 - /usr/bin/xcodebuild
  Languages:
    Java: 15.0.2 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.68.0 => 0.68.0 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Library version: 12.3.0 / 12.1.0

Steps To Reproduce

Try to render the SVG provided.

Describe what you expected to happen:
The SVG to render properly :)

@antondalgren
Copy link
Author

Updated minimal reproducible SVG.
The crash only occurs in iOS simulator.

<svg width="290" height="500" viewBox="0 0 290 500" xmlns="http://www.w3.org/2000/svg" xmlns:xlink='http://www.w3.org/1999/xlink'>
<defs>
  <path id="text-path-a" d="M40 12 H250 A28 28 0 0 1 278 40 V460 A28 28 0 0 1 250 488 H40 A28 28 0 0 1 12 460 V40 A28 28 0 0 1 40 12 z" />
</defs>
<text>
  <textPath startOffset="1%" xlink:href="#text-path-a">
    ahshjkdasjklsadjkldasjkldsajklkljsdakjlcsakljdjklaskljdjsakldjaksl
  </textPath>
  <textPath startOffset="1%" xlink:href="#text-path-a">
    ahshjkdasjklsadjkldasjkldsajklkljsdakjlcsakljdjklaskljdjsakldjaksl
  </textPath>
  <textPath startOffset="1%" xlink:href="#text-path-a">
    ahshjkdasjklsadjkldasjkldsajklkljsdakjlcsakljdjklaskljdjsakldjaksl
  </textPath>
  <textPath startOffset="1%" xlink:href="#text-path-a">
    ahshjkdasjklsadjkldasjkldsajklkljsdakjlcsakljdjklaskljdjsakldjaksl
  </textPath>
</text>
</svg>

@antondalgren
Copy link
Author

Turns out that the crash happens due to an index out of bounds exception.

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndexedSubscript:]: index 69 beyond bounds [0 .. 68]'

The error originates from this part of the code: https://github.com/react-native-svg/react-native-svg/blob/54e40251a491bb1a2d0a75e4748a23ea24fb3f6b/apple/Utils/RNSVGPathMeasure.m#L193-L211

If we have an array_lengths of [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17] giving _linecount a value of 18, and we end up in the else statement of the ternary. When the item we are trying to insert in the array is 20, using the binary search insertion index option, we will get an index of 19, which is where we should place 20.

Later, at line 210, we try to extract the the value from an item at index 19, but our array, lengths is only 18 items long giving us an index out of bounds exception.

I'm not very familiar with objective C, but do you think adding this between line 208 and 210 could be the solution to this?

if(i >= _lineCount) {
    i = _lineCount - 1;
}

@antondalgren
Copy link
Author

Some additional comments on the transform:translate and transform:translate3d issues is that it looks like it doesn't have support for the translate3d property at all ([SyntaxError: Expected "(" or [ \t\r\n] but "3" found.]).

And that the translate directive does not support being used with pixel values. eg: transform:translate(226px, 433px) gives the error [SyntaxError: Expected ")", ",", [ \t\r\n], [0-9], or [eE] but "p" found.]

@antondalgren
Copy link
Author

Any comments on this? @WoLewicki Is there something I can do?

@steven-isbell
Copy link

Any traction on this? We're seeing this issue as well

@Moatezz
Copy link

Moatezz commented Dec 27, 2022

same here when trying to render animated svg

@see2ever
Copy link

any news?

@devnshankar
Copy link

devnshankar commented Dec 9, 2023

Similar issue but in my case I was trying to use the tamagui ui component library's lucide icons, which maybe at the core is a svg, i wasn using it with the YGroup and listItem component to display a group of items each of which is a button which an icon at the left and the right and text in between of the item area,

I almost finished my app and used eas build for the apk , everything was working fine but the pages which had used those lucide icons when clicked upon or rendered, immidiately crashed.

I tried to use the logcat and read the logs of the application and found nothing. But then when i read the logs of gradlew at the expo site there were many warnings about various things but this one particular warning caught my eye regarding the svg and on an article also I noticed someone else with the same issue and installing this react-native-svg package and running

npx expo-doctor

to check the required version and reinstalling the required one if needed, solved their issue. Well i have not tried it yet I just found out this issue that was similar so thought i'd contribute something to it.

I'll update if i find any solutions.


UPDATE

Turns out my issue is now resolved as i said before it was the svg issue and i finally got down to it , I installed the mentioned react native svg module and for better I stopped using the svg in the first place as icons i'm using the inbuilt icons of react native vector icons and they work fine, in the begining i also thought that it might be a loading or rendering issue which is breaking the app and crashing the apk when installed on device but it was the SVG issue.
I hope the team finds out why this issue is occuring in the first place. I'm not sure what worked for me the svg module or me not using svg. I guess that's for another day and another sleepless night scratching my head untill i go bald on a issue like this.

Feel free to ask any questions. if any !!!

@mthonorio
Copy link

Same problem here, which used app in Expo Go render SVGs smooth, but in development build or APK the app crash.

@bohdanprog
Copy link
Member

Hello @mthonorio,
Can you please share the simple example app with us?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants