Phrogz / svg-path-to-polygons

Converts path commands for an SVG path to polygon points.
MIT License
55 stars 19 forks source link

Exceeded Call Stack #7

Open dp1140a opened 4 years ago

dp1140a commented 4 years ago

773k world.svg

When running i get the following:

svg2geojson --layers -m world.svg Ignoring unhandled element text Ignoring unhandled element text Ignoring unhandled element text Ignoring unhandled element text Ignoring unhandled element text Ignoring unhandled element text Ignoring unhandled element text Ignoring unhandled element text Ignoring unhandled element text Ignoring unhandled element text Ignoring unhandled element text Ignoring unhandled element text Ignoring unhandled element text Ignoring unhandled element text Ignoring unhandled element text Ignoring unhandled element text events.js:187 throw er; // Unhandled 'error' event ^

RangeError: Maximum call stack size exceeded at sampleCubicBézier (/usr/local/lib/node_modules/svg2geojson/node_modules/svg-path-to-polygons/svg-path-to-polygons.js:55:28) at sampleCubicBézier (/usr/local/lib/node_modules/svg2geojson/node_modules/svg-path-to-polygons/svg-path-to-polygons.js:79:5) at sampleCubicBézier (/usr/local/lib/node_modules/svg2geojson/node_modules/svg-path-to-polygons/svg-path-to-polygons.js:79:5) at sampleCubicBézier (/usr/local/lib/node_modules/svg2geojson/node_modules/svg-path-to-polygons/svg-path-to-polygons.js:79:5) at sampleCubicBézier (/usr/local/lib/node_modules/svg2geojson/node_modules/svg-path-to-polygons/svg-path-to-polygons.js:79:5) at sampleCubicBézier (/usr/local/lib/node_modules/svg2geojson/node_modules/svg-path-to-polygons/svg-path-to-polygons.js:79:5) at sampleCubicBézier (/usr/local/lib/node_modules/svg2geojson/node_modules/svg-path-to-polygons/svg-path-to-polygons.js:79:5) at sampleCubicBézier (/usr/local/lib/node_modules/svg2geojson/node_modules/svg-path-to-polygons/svg-path-to-polygons.js:79:5) at sampleCubicBézier (/usr/local/lib/node_modules/svg2geojson/node_modules/svg-path-to-polygons/svg-path-to-polygons.js:79:5) at sampleCubicBézier (/usr/local/lib/node_modules/svg2geojson/node_modules/svg-path-to-polygons/svg-path-to-polygons.js:79:5) Emitted 'error' event on Parser instance at: at Parser.exports.Parser.Parser.parseString (/usr/local/lib/node_modules/svg2geojson/node_modules/xml2js/lib/parser.js:327:16) at Parser.parseString (/usr/local/lib/node_modules/svg2geojson/node_modules/xml2js/lib/parser.js:5:59) at loadFromString (/usr/local/lib/node_modules/svg2geojson/lib/svg2geojson.js:21:3) at loadFromFile (/usr/local/lib/node_modules/svg2geojson/lib/svg2geojson.js:15:2) at Object. (/usr/local/lib/node_modules/svg2geojson/bin/svg2geojson:41:1)

Phrogz commented 4 years ago

Thanks for the report. Looks like adaptive subsampling algorithm I reused uses recursion and for some reason dove too deep on a particular path. The tolerance might need to be adjusted, but it's currently calculated by the library.

If you have the time, I'd appreciate it if you can either share the SVG that caused this issue, or (if its proprietary) pare it down to find the path in question causing the issue.

AlexsandroProjetosOficial commented 4 years ago

@Phrogz

When executing a svg the following error appears below, how can I fix it:

(node:9140) UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded at sampleCubicBézier (F:\SystemRedeAll\APIs\api_biblioteca\node_modules\svg-path-to-polygons\svg-path-to-polygons.js:55:28) at sampleCubicBézier (F:\SystemRedeAll\APIs\api_biblioteca\node_modules\svg-path-to-polygons\svg-path-to-polygons.js:79:5) at sampleCubicBézier (F:\SystemRedeAll\APIs\api_biblioteca\node_modules\svg-path-to-polygons\svg-path-to-polygons.js:79:5) at sampleCubicBézier (F:\SystemRedeAll\APIs\api_biblioteca\node_modules\svg-path-to-polygons\svg-path-to-polygons.js:79:5) at sampleCubicBézier (F:\SystemRedeAll\APIs\api_biblioteca\node_modules\svg-path-to-polygons\svg-path-to-polygons.js:79:5) at sampleCubicBézier (F:\SystemRedeAll\APIs\api_biblioteca\node_modules\svg-path-to-polygons\svg-path-to-polygons.js:79:5) at sampleCubicBézier (F:\SystemRedeAll\APIs\api_biblioteca\node_modules\svg-path-to-polygons\svg-path-to-polygons.js:79:5) at sampleCubicBézier (F:\SystemRedeAll\APIs\api_biblioteca\node_modules\svg-path-to-polygons\svg-path-to-polygons.js:79:5) at sampleCubicBézier (F:\SystemRedeAll\APIs\api_biblioteca\node_modules\svg-path-to-polygons\svg-path-to-polygons.js:79:5) at sampleCubicBézier (F:\SystemRedeAll\APIs\api_biblioteca\node_modules\svg-path-to-polygons\svg-path-to-polygons.js:79:5) at sampleCubicBézier (F:\SystemRedeAll\APIs\api_biblioteca\node_modules\svg-path-to-polygons\svg-path-to-polygons.js:79:5) at sampleCubicBézier (F:\SystemRedeAll\APIs\api_biblioteca\node_modules\svg-path-to-polygons\svg-path-to-polygons.js:79:5) at sampleCubicBézier (F:\SystemRedeAll\APIs\api_biblioteca\node_modules\svg-path-to-polygons\svg-path-to-polygons.js:79:5) at sampleCubicBézier (F:\SystemRedeAll\APIs\api_biblioteca\node_modules\svg-path-to-polygons\svg-path-to-polygons.js:79:5) at sampleCubicBézier (F:\SystemRedeAll\APIs\api_biblioteca\node_modules\svg-path-to-polygons\svg-path-to-polygons.js:79:5) at sampleCubicBézier (F:\SystemRedeAll\APIs\api_biblioteca\node_modules\svg-path-to-polygons\svg-path-to-polygons.js:79:5) (node:9140) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)

svg: <?xml version="1.0" encoding="utf-8"?>

<svg version="1.1" id="x30" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1366 768" style="enable-background:new 0 0 1366 768;" xml:space="preserve">

svg.txt

richardstefun commented 3 years ago

If you have the time, I'd appreciate it if you can either share the SVG that caused this issue, or (if its proprietary) pare it down to find the path in question causing the issue.

Hello, I was able to detect the path that causes this issue:

M120.5,350.2c0-0.7,0.1-1.6,0.1-1.6c0-0.6,0.1-1,0.1-1.3c-0.3,0.3-0.6,0.6-1,0.9c-5.9,4.8-17.9,6-24.1-0.8 c-3.7-4.1-5.7-11.4-2.3-16.4c1.8-2.6,5-4.5,8.4-4.7c1.1,0,4.9-0.2,7.2,2.7c1.4,1.8,2,4.4,1.2,6.7c-0.2,0.6-0.9,2.8-3.1,3.9 c-2.1,0.9-4.9,0.6-6.4-1.2c-1.5-1.8-1.3-4.3-1.2-4.4c0,0,0,0,0,0c0-0.2-0.8-0.3-1.1-0.2c-0.8,0.2-1.3,2.5-1,4.2 c0.5,3.1,3.5,5.3,6,6.3c5.7,2.2,11.3-1.5,12.5-2.2c5.3-3.4,7-8.8,7.4-10.5c0.4,0.4,0.8,0.8,1.2,1.2c1.5,1.3,3,2.2,4.3,2.8 c-0.1,0.4-0.2,0.9-0.3,1.6c-1.2,7.2-1.7,20.6,3.8,23.1c1.9,0.9,4.8,0.4,4.9-0.2c0.1-0.6-0.2-0.8-0.2-0.8l-1.3-1.1 c-0.9-0.8-1-2.5-0.7-3.8c0.6-2.1,2.6-3,2.9-3.1c2.6-1.1,4.9,0.5,5.1,0.6c2.1,1.4,2.4,4,2.5,5.5c0.3,2.9-1.3,7.9-4.7,9.7 c-7.1,3.8-13.7-0.5-17.3-6.2C121,357.2,120.4,354,120.5,350.2z

I hope it can help you find the issue :)

Crisfole commented 2 years ago

@Phrogz for us this is usually curves where the start and end points are the same.