annotorious / annotorious-v1

Project has moved to http://github.com/annotorious/annotorious
https://annotorious.com
MIT License
593 stars 143 forks source link

Cannot read property type of undefined #181

Open dhruvp opened 7 years ago

dhruvp commented 7 years ago

Hi!

First of all thank you so much for creating and maintaining annotorious for the broader public. It has been a joy to use and has made our lives so much better!

One issue we've been seeing every so often is when we hit edit on an annotation, we get a javascript error in annotorious:

Uncaught TypeError: Cannot read property 'type' of undefined
    at http://127.0.0.1:8080/js/annotorious.min.js:215:107
    at Da (http://127.0.0.1:8080/js/annotorious.min.js:7:92)

I've done my best at understanding why that happens and it seems to me that it corresponds to the code here:

https://github.com/annotorious/annotorious/blob/b3a1db3bf21abccd8b44b3e0c6c2b6479b11b1a9/src/mediatypes/image/image.viewer.js#L245-L248

What's happening is shape is a null object as passed in. This happens because the given shape is for some reason not in self._shapes as in this code snippet:

      self._draw(self._shapes[annotorious.shape.hashCode(annotation.shapes[0])]);

This seems to happen somewhat randomly - most annotations in the same image work but the odd annotation will cause this error.

Would you please be able to help us debug this?

Thank you!

Dhruv

dhruvp commented 7 years ago

One more thing - I think it's related to the fact that self._currentAnnotation is undefined in the pass through this code block:

  goog.array.forEach(this._annotations, function(annotation) {
    if (annotation != self._currentAnnotation)
      self._draw(self._shapes[annotorious.shape.hashCode(annotation.shapes[0])]);
  });

As such, we try to draw the annotation that's being edited which I think is causing the issue? Still trying to figure out how self._currentAnnotation is set.

dhruvp commented 7 years ago

Ok I found the issue. It happens when you have two keypoints in the exact same position. This is because we delete from an array (this._annotations) leaving one item still in that array, but the dictionary self._shapes no longer has it. Not sure if it's worth addressing or not but seems like an edge case potentially worth addressing.