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

I find endless loop in Layer.getIntersection #1060

Open
DMIAOCHEN opened this issue Mar 14, 2015 · 1 comment
Open

I find endless loop in Layer.getIntersection #1060

DMIAOCHEN opened this issue Mar 14, 2015 · 1 comment

Comments

@DMIAOCHEN
Copy link

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
Copy link
Author

maybe this variable should be defined in for loop?

var continueSearch = false;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant