KineticJS icon indicating copy to clipboard operation
KineticJS copied to clipboard

I find endless loop in Layer.getIntersection

Open DMIAOCHEN opened this issue 9 years ago • 1 comments

can not out the while, and now in order to avoid endless loop, i add some code like this, this right?

if (spiralSearchDistance > this.width()) {
                            return null;
                        }
getIntersection: function(pos) {
            var obj, i, intersectionOffset, shape;

            if(this.hitGraphEnabled() && this.isVisible()) {
                // in some cases antialiased area may be bigger than 1px
                // it is possible if we will cache node, then scale it a lot
                // TODO: check { 0; 0 } point before loop, and remove it from INTERSECTION_OFFSETS.
                var spiralSearchDistance = 1;
                var continueSearch = false;
                while (true) {
                    for (i=0; i<INTERSECTION_OFFSETS_LEN; i++) {
                        intersectionOffset = INTERSECTION_OFFSETS[i];
                        obj = this._getIntersection({
                            x: pos.x + intersectionOffset.x * spiralSearchDistance,
                            y: pos.y + intersectionOffset.y * spiralSearchDistance
                        });
                        shape = obj.shape;
                        if (shape) {
                            return shape;
                        }
                        // we should continue search if we found antialiased pixel
                        // that means our node somewhere very close
                        else if (obj.antialiased) {
                            continueSearch = true;
                        }
                    }
                    // if no shape, and no antialiased pixel, we should end searching 
                    if (continueSearch) {
                        spiralSearchDistance += 1;
                       // now i do this avoid endless loop, it's Right?
                        if (spiralSearchDistance > this.width()) {
                            return null;
                        }
                    } else {
                        return;
                    }
                }
            } else {
                return null;
            }
        }

DMIAOCHEN avatar Mar 14 '15 10:03 DMIAOCHEN