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

Cannot read property 'left' of null #36

Closed
jliebrand opened this issue Sep 26, 2018 · 23 comments
Closed

Cannot read property 'left' of null #36

jliebrand opened this issue Sep 26, 2018 · 23 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@jliebrand
Copy link
Contributor

Reproduce case: https://repl.it/repls/TangibleHoneydewFiber

As far as I can make out, the input geometry should be valid, but it clearly barfs on some aspect of it... Still trying find which of the polygons is causing the problem...

@jliebrand
Copy link
Contributor Author

Another case where the same exception is thrown for a different dataset:

https://repl.it/repls/IdenticalBuzzingTruespace

@jliebrand
Copy link
Contributor Author

Furthermore, on the first dataset, if I try to narrow down which geom is causing the problems, I see this;

polygonClipping.union(featureCollection().slice(2,3))

Uncaught Error: Input has more than two coordinates. Only 2-dimensional polygons supported.

Not sure if that's related at all though?

@jliebrand
Copy link
Contributor Author

I suspect this might be related to issue #29 and I am curious about this line of code (from the fix for that bug):

https://github.com/mfogel/polygon-clipping/blob/master/src/segment.js#L58

Shouldn't that be

if (a.isVertical !== b.isVertical) return (a.isVertical ? -1 : 1)

At the moment it will return just a.isVertical, which is either true or false, and when false the compare function will thus claim the two segments are identical? Or is that actually the intention? (still wrapping my head around the algo and code)

@jliebrand
Copy link
Contributor Author

(note: my previous comment doesn't fix/change the issue. But it seemed odd)

@mfogel mfogel added the bug Something isn't working label Sep 27, 2018
@mfogel mfogel self-assigned this Sep 27, 2018
@jliebrand
Copy link
Contributor Author

Hi @mfogel , thanks for picking this up... any ideas what the issue might be (and/or if there is a quick workaround at the moment)? We're seeing these errors crop up quite a number of times now for our end users; so keen to get a fix in place (even if it's a temporary work around)

mfogel added a commit that referenced this issue Sep 28, 2018
@mfogel
Copy link
Owner

mfogel commented Sep 28, 2018

Hi @jliebrand , thanks for the bug report

Not sure on any easy workarounds.... once I get a chance to deep dive into these shapes and understand what's going wrong I may be able to recommend a work-around. In the past rounding errors have often caused bugs like these, but looking at your shapes I see ~6 decimals not ~12, so I think rounding errors are probably not the cause of the problem, but can't say for sure at this point.

I don't have time to deep dive into this today, but might this weekend.

My process for debugging this will be:

  1. transform the shapes you have in those two Repl.it examples into one or more failing end-to-end test cases. This means adding at least one directory to this dir with at least two files - args.geojson and union.geojson
  2. simplify the failing test cases. Reduce the polygons in args.geojson to the simplest possible polygons that still trigger the bug.
  3. step through the algorithm manually to try to figure out what's going wrong.

I'll use this line to focus on one failing end-to-end test case at a time.

I'll use tools like mapshaper.org and geojsonhint to visualize the shapes and makes sure they're well-formed.

If you want to help things along, if you can fork this project, make a branch and do the first one or two steps that'll save me time.

And - thanks for pointing out that bug in Segment.compare - it should be fixed now on master.

Cheers

@jliebrand
Copy link
Contributor Author

Great - I'll have a look at adding tests to cover this and try to get a minimum repro case

@jliebrand
Copy link
Contributor Author

Interesting - I can not reproduce the crash on master... it still crashes on the version from 30th aug (eg the released version), but it seems to work on the latest...

Time for an updated release?

@jliebrand
Copy link
Contributor Author

It seems this commit:
d0ce1ef

Fixed this problem. We have a few more errors in our logs, I will check if those are also fixed with that commit or not. And if not, put some test cases in

@jliebrand
Copy link
Contributor Author

I'll leave this bug open until that commit is released, but it does indeed appear to have solved the problem.

There is however another bug where the input causes an infinite loop somewhere. I've raised a new issue (#38 ) and a PR to add a test case for it.

@mfogel mfogel added this to the 0.9 milestone Oct 2, 2018
mfogel added a commit that referenced this issue Oct 2, 2018
Formed from one of the failing inputs linked on that ticket.

This is broken in the latest release to npm (v0.8) but already fixed on
master. Adding this test case to make sure this is covered by the test
suite.
@mfogel
Copy link
Owner

mfogel commented Oct 2, 2018

Glad to see it's already fixed! Thanks for tracking this further down @jliebrand

To make sure the test suite covers this case, I added a test case to master anyway of a mostly-simplified geometry based off one of the ones you provided above, which triggers a failure on v0.8 but passes on master.

I'll release a v0.9 with this fix once the other open bugs are either fixed or understood to be a enough work to justify pushing them to v0.10

@jliebrand
Copy link
Contributor Author

I think I might have spoken too soon. Looks like these coordinates still cause this bug to trigger:

https://gist.github.com/jliebrand/8aa87238df614d1c5d456af98fd0ad49

@jliebrand
Copy link
Contributor Author

Hi @mfogel - I know you're busy, but any update on this and the other bugs?

@mfogel
Copy link
Owner

mfogel commented Oct 16, 2018

@jliebrand sorry for the pause. I'll make time tonight / tomorrow to review at least some of the other open bugs & PR's and release a v0.9 regardless so that at least this fix can be pushed out to npm.

@jliebrand
Copy link
Contributor Author

Great - thanks!

@mfogel
Copy link
Owner

mfogel commented Oct 18, 2018

Just released v0.9 that has the fix to this in it.

@mfogel mfogel closed this as completed Oct 18, 2018
@jliebrand
Copy link
Contributor Author

Did you see my comment
#36 (comment)

Not sure 0.9 fixes that? Unless you made another change?

@mfogel
Copy link
Owner

mfogel commented Oct 18, 2018

@jliebrand sorry missed your comment. I just verified it's still broken on those coordinates - reopening this bug.

@mfogel mfogel reopened this Oct 18, 2018
@jliebrand
Copy link
Contributor Author

@mfogel how are things going with this (and the other) bugs?

@jliebrand
Copy link
Contributor Author

ps. it doesn't look like 0.9 is on npm yet?

@mfogel
Copy link
Owner

mfogel commented Oct 23, 2018

I think v0.9 is on npm. (there is a mistake in the README on there, it says that v0.9 is still 'in development')

I should get a few hours to process through the open bugs on saturday and sunday. In general, if they turn out not to be floating-point rounding issues, they're a lot easier to fix.

@jliebrand
Copy link
Contributor Author

Ah great! I used npm-check to see if there was an update and it didn't report it. But that's probably because I have the module pointed directly to github. I'll have to keep that for now, as 0.9 does not have the guard against the eternal loop. But I'll update my package.json once the other bugs are fixed.

@mfogel
Copy link
Owner

mfogel commented Oct 27, 2018

Ok, I've reduced the error condition to applying a union to these shapes:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [[0.0, 1.0], [0.0, 1.04], [0.08, 1.02], [0.14, 1.04], [0.0, 1.0]]
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [[[0.08, 1.02], [0.0, 1.0], [0.0, 1.04], [0.08, 1.02]]]
      }
    }
  ]
}

They look pretty harmless, but there are a few identical segments in those two polygons, which I suspect is triggering the bug. Stay tuned!

@mfogel mfogel closed this as completed in 9c82aba Oct 27, 2018
@mfogel mfogel modified the milestones: 0.9, v0.9.1 Oct 27, 2018
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

2 participants