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

Maximum call stack size exceeded #111

Open
Tracked by #1
nikkigantos opened this issue Jan 30, 2021 · 2 comments
Open
Tracked by #1

Maximum call stack size exceeded #111

nikkigantos opened this issue Jan 30, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@nikkigantos
Copy link

Have been repeatedly hitting a Maximum call stack size exceeded when trying to perform a union operation on a multi-polygon:

    const newGeo = union(originalMultipolygon, additionalGeometry);

Below are the additional and original geometries. The original multi-polygon seems to be the source of the error (as I've attempted the union with a several additional regions, all of which return this call stack error). Curious what could be causing call stack error for this case?

// Additional Geometry (additionalGeometry): 
[[[[777.538,129.923],[778,129],[779,128],[781,127],[784,126],[786,125],[790,124],[790,123],[789,122],[789,119],[793,115],[794,115],[794,114],[795,114],[796,113],[797,113],[799,115],[800,115],[804,119],[804,120],[805,121],[805,123],[806,124],[806,130],[805,130],[804,131],[803,131],[803,132],[802,132],[801,133],[799,133],[799,133.088],[778,130],[777.538,129.923]]]]
// Original Multi-polygon (originalMultipolygon):
[[[[363,131],[363.909,142.818],[363.7,140.1],[364,141],[364,143],[366,147],[373,156],[382,166],[388,175],[394,177],[396,175],[395,175],[395,167],[393,160],[393,153],[394,152],[394,151],[395,150],[396,146],[396,145],[397,145],[398,140],[397,128],[398,131],[400,141],[401,139],[401,145],[402,153],[404,160],[406,163],[407,163],[408,160],[408,154],[410,146],[413,138],[413.385,137.692],[408,135],[400,129],[396,125],[393,121],[389,115],[388,110],[388,101],[391,96],[406,81],[412.5,72.875],[409,79],[401,87],[396,93],[395,94],[390,101],[390,102],[391,108],[391,114],[397,124],[407,132],[415.877,135.699],[418,134],[424,130],[430,129],[438,127],[438,124],[429,123],[422,122],[417,119],[413,117],[410,114],[408,110],[407,110],[405,105],[405,104],[404,98],[405,90],[406,84],[411,80],[414,78],[409,84],[407,91],[407,103],[408,108],[411,112],[413,116],[421,120],[428,122],[440,122],[441,120],[441,118],[437,114],[434,109],[430,102],[427,86],[429,93],[434,103],[440,112],[441,112],[442,111],[440,107],[435,92],[434,78],[435,88],[439,98],[443,106],[443,104],[445,98],[449,87],[449,86],[452,80],[459,70],[470,61],[482,50],[496,42],[500,37],[503,33],[510,28],[514,24],[521,22],[535,15],[543,13],[544,13],[556,11],[568,14],[579,19],[593,24],[606,29],[617,31],[618,31],[618,32],[620,33],[622,32],[622,30],[621,27],[623,29],[624,32],[624,33],[625,34],[629,26],[632,23],[635,21],[636,18],[636,13],[634,7],[632,3],[629,0],[634,0],[636,7],[639,13],[639,20],[638,24],[635,28],[631,31],[626,34],[624,36],[626,36],[630,37],[635,41],[639,44],[643,50],[644,50],[644,52],[645,53],[645,56],[647,57],[653,58],[658,56],[661,55],[665,52],[669,46],[671,36],[670,43],[670,45],[671,44],[673,39],[675,33],[674,40],[672,45],[672,46],[669,52],[676,51],[672,53],[669,55],[667,58],[669,59],[675,67],[675,68],[676,68],[676,67],[675,64],[674,60],[674,59],[675,60],[679,67],[681,75],[681,79],[686,81],[692,80],[689,83],[688,83],[687,84],[686,84],[685,85],[688,91],[699,91],[700,92],[706,94],[715,104],[735,119],[736,121],[737,121],[743,118],[751,115],[759,115],[764,116],[769,120],[775,127],[775,128],[774,128],[774,129],[773,128],[772,129],[778,130],[812,135],[815,135],[822,132],[827,130],[837,130],[843,131],[848,134],[849,134],[849,135],[850,136],[850,137],[849,137],[849,138],[848,138],[848,139],[847,139],[847,140],[855,141],[860,143],[868,153],[868.714,160.143],[867,155],[865,152],[865,162],[866,169],[862,159],[860,151],[854,145],[850,144],[844,144],[849,148],[853.154,152.615],[843,145],[839,143],[830,143],[822,144],[822,145],[823,147],[823,153],[825,154],[832,160],[830,160],[826,158],[823,157],[818,157],[818,158],[820,158],[820,160],[821,160],[821,159],[822,159],[822,160],[823,160],[823,163],[832,163],[833,164],[833,165],[832,166],[831,166],[831,167],[826,167],[826,168],[827,169],[831,169],[835,173],[843,173],[844,172],[852,172],[858,173],[863,177],[868,180],[869.2,183.2],[867,181],[863,178],[859,177],[854,177],[849,178],[850,178],[851,179],[855,181],[862,185],[866,190],[868,190],[868,191],[869,191],[870,194],[873,199],[877,206],[879,214],[882,216],[887,220],[894,229],[892,228],[888,227],[882,225],[882,226],[883,226],[883,227],[884,227],[884,228],[885,229],[885,233],[888,234],[892,234],[893,233],[891,236],[879,242],[879,248],[878,248],[877,247],[877,245],[874,244],[870,246],[874,253],[876,262],[877,270],[877,274],[876,274],[876,273],[875,272],[875,270],[874,270],[874,268],[873,268],[873,270],[872,271],[872,274],[871,274],[871,275],[870,275],[870,276],[869,276],[869,274],[868,273],[868,271],[867,271],[867,272],[866,272],[866,273],[865,273],[865,266],[863,257],[861,252],[858,250],[852,248],[843,251],[842,251],[842,252],[843,252],[843,253],[846,254],[851,263],[857,271],[865,277],[872,279],[880,279],[887,278],[887,277],[896,274],[901,272],[908,267],[906,270],[899,276],[889,282],[890,283],[896,282],[900,282],[901,281],[909,279],[918,279],[916,280],[906,282],[901,285],[897,288],[898,289],[901,290],[907,294],[904,293],[899,291],[893,290],[871,292],[860,292],[864,296],[860,294],[855,290],[846,286],[840,282],[840,286],[839,299],[838,303],[835,307],[835,308],[833,309],[831,311],[831,312],[826,314],[828,313],[831,310],[831,309],[832,308],[832,307],[831,307],[831,306],[832,305],[832,301],[831,297],[827,289],[826,289],[822,290],[817,294],[810,296],[804,295],[796,291],[785,292],[792,296],[809,308],[819,318],[826,328],[819,321],[812,313],[795,300],[781,292],[774,289],[782,295],[797,305],[809,314],[815,319],[819,326],[821,331],[820,337],[820,340],[819,343],[816,347],[809,355],[814,349],[817,344],[819,341],[819,335],[818,331],[816,328],[812,323],[802,317],[789,308],[775,298],[762,286],[745,272],[737,264],[737,263],[734,259],[733,258],[731,254],[730,254],[726,249],[717,244],[711,237],[701,227],[696,224],[680,229],[674,227],[674,226],[673,224],[673,219],[674,218],[674,217],[675,217],[675,216],[676,215],[677,215],[677,214],[678,214],[678,211],[672,211],[667,208],[660,202],[657,201],[656,202],[656,211],[654,228],[640,264],[630,279],[624,286],[617,292],[612,294],[607,294],[601,293],[590,289],[581,282],[568,276],[554,271],[538,263],[531,258],[528,255],[520,249],[519,249],[507,242],[504,240],[498,239],[495,239],[492,241],[488,245],[488,246],[487,246],[487,247],[486,246],[485,246],[481.077,242.077],[478,249],[473,256],[462,262],[458.726,262.982],[460,261],[451,275],[444,283],[435,290],[428,291],[419,290],[411,289],[403,286],[398,282],[395,281],[394,281],[392,282],[390,285],[388,287],[390,282],[392,279],[393,278],[400,278],[405,280],[415,283],[424,284],[431,283],[436,280],[441,276],[444,273],[449,267],[450.444,265.556],[438,270],[443,268],[448,265],[439,262],[438,261],[447,263],[452,263],[453.625,262.375],[455,261],[458,255.75],[457.857,256],[456,256],[456,257],[454,257],[454,253],[452,253],[452,252],[453,252],[453,251],[455,251],[455,249],[453,249],[453,248],[452,248],[452,247],[454,247],[457,247.429],[457,246],[457.333,245.667],[454,239],[454,222],[455,221],[455,220],[455.063,219.875],[451,215],[446,208],[445,210],[441,214],[437,217],[432,219],[426,219],[425,220],[425,221],[429,223],[432,222],[434,225],[432,231],[432,227],[430,225],[405,218],[390,209],[387,206],[386,206],[386,205],[385,205],[385,204],[384,203],[384,202],[383,202],[383,198],[384,198],[384,197],[385,196],[385,195],[386,195],[386,190],[385,189],[385,188],[384,188],[384,186],[382,186],[381,185],[381,183],[382,183],[382,181],[383,181],[383,177],[382,177],[382,175],[381,175],[381,174],[385,176],[384,172],[377,161],[365,148],[364.4,145.6],[364,145],[364,144],[363.75,142.5],[363,141],[363,131]],[[458,255.75],[458.429,255],[458,255],[458,255.75]],[[457.333,245.667],[458,245],[459,245],[459,244],[458,244],[458,241],[459,241],[459,242],[460,242],[460,243],[461,244],[461,245],[462,245],[462,245.5],[463,243],[464,237],[465,236],[465,231],[462,228],[456,221],[456,237],[457.667,245.333],[457.333,245.667]],[[409,156],[409,161],[410,165],[410,163],[411,162],[411,154],[412,153],[412,151],[413,151],[413,159],[415,161],[418,160],[423,158],[427,155],[416,155],[416,154],[415,154],[420,151],[427,147],[428,147],[434,144],[437,142],[425,142],[419,141],[416,139],[410,151],[409,156]],[[420,135],[420,137],[428,137],[435,138],[436,137],[436,136],[437,135],[437,133],[438,133],[437,132],[429,131],[426,132],[424,132],[424,133],[423,133],[422,134],[421,134],[421,135],[420,135]],[[432,214],[433,214],[434,213],[436,213],[437,212],[438,212],[441,209],[443,206],[439,210],[435,212],[432,214]],[[456,250],[456,253],[457,253],[457,254],[459,254],[459,253],[460.6,249],[458,249],[458,250],[456,250]],[[460.886,259.582],[465,258],[469,255],[475,247],[479,237],[475,237],[474,238],[472.5,238],[474,237],[475,236],[478,236],[478,235],[480,233],[479,232],[474,230],[473,229],[473,228],[472,228],[472,227],[471,226],[471,223],[470,223],[470,222],[468,222],[468,221],[466,221],[466,220],[464,220],[464,221],[470,227],[472,233],[471,236],[470,241],[466,252],[465,253],[460.886,259.582]],[[466,215],[466,216],[467,217],[468,217],[468,215],[466,215]],[[471,214],[471,218],[473,220],[475,220],[476,219],[475,218],[474,218],[472,216],[471,214]],[[474,224],[474,226],[475,227],[477,228],[477,229],[478,229],[478,224],[476,225],[475,224],[474,224]],[[482,233],[482,235],[483,236],[483,237],[485,237],[485,236],[486,236],[486,235],[485,235],[485,234],[484,234],[482,233]]],[[[401,138],[402,137],[401,139],[401,138]]],[[[412.5,72.875],[413,72],[414,71],[412.5,72.875]]],[[[414,78],[417,76],[425,74],[418,76],[414,78]]],[[[429,235],[430.8,232.6],[430,235],[429,236],[429,235]]],[[[430.8,232.6],[431,232],[431.25,232],[430.8,232.6]]],[[[431.25,232],[432,231],[432,232],[431.25,232]]],[[[472.5,238],[471,239],[472,238],[472.5,238]]],[[[670,56],[671,57],[670,57],[670,56]]],[[[671,57],[672,57],[674,59],[673,59],[671,57]]],[[[853.154,152.615],[855,154],[858,158],[853.154,152.615]]],[[[866,169],[867,169],[867,170],[866,169]]],[[[868.714,160.143],[869,161],[869,163],[868.714,160.143]]],[[[869.2,183.2],[871,185],[871,188],[869.2,183.2]]]]
@adamwong246
Copy link

+1

@mcwhittemore
Copy link

From what I can tell this is being caused by the recursion in isExteriorRing. Locally I converted the recursion into a loop and got an out of memory error. This made me assume that enclosingRing was causing an infinite loop. To test that theory I rewrote the isExteriorRing function to so that memory wouldn't overflow and sure enough the program didn't crash. Though it also never returned a result. The two rewrites are below.

Out of memory example

function isExteriorRing() {
    var rings = [this]
    var idx = 0;
    while(rings[idx]._isExteriorRing === undefined) {
      var enclosing = rings[idx].enclosingRing();
      if (enclosing) {
        rings.push(enclosing);
        idx++;
      } else {
        rings[idx]._isExteriorRing = true;
      }
    }
    for(let i=rings.length-2; i>=0; i--) {
      rings[i]._isExteriorRing = !rings[i+1]._isExteriorRing;
    }
    return this._isExteriorRing;
  }
}

Infinite loop example

function isExteriorRing() {
  if (this._isExteriorRing === undefined) {
    var ring = this
    var idx = 0;
    while(ring._isExteriorRing === undefined) {
      var enclosing = ring.enclosingRing();
      if (enclosing) {
        ring = enclosing;
        idx++;
      } else {
        ring._isExteriorRing = true;
      }
    }
    this._isExteriorRing = ring._isExteriorRing;
    for(let i=0; i<idx; i++) {
      this._isExteriorRing = !this._isExteriorRing;
    }     
  }
  return this._isExteriorRing;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants