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

Calling InteractionManager.hitTest throws an exception #74

Open
soylomass opened this issue Jul 27, 2021 · 3 comments
Open

Calling InteractionManager.hitTest throws an exception #74

soylomass opened this issue Jul 27, 2021 · 3 comments

Comments

@soylomass
Copy link

The InteractionManager's hitTest method calls processInteractive with the func parameter as null:

public hitTest(globalPoint: Point, root?: DisplayObject): DisplayObject
    {
        // clear the target for our hit test
        hitTestEvent.target = null;
        // assign the global point
        hitTestEvent.data.global = globalPoint;
        // ensure safety of the root
        if (!root)
        {
            root = this.lastObjectRendered;
        }
        // run the hit test
        this.processInteractive(hitTestEvent as InteractionEvent, root, null, true);
        // return our found object - it'll be null if we didn't hit anything

        return hitTestEvent.target;
    }

processInteractive then calls LayersTreeSearch's findHit

public processInteractive(interactionEvent: InteractionEvent, displayObject: DisplayObject,
        func?: InteractionCallback, hitTest?: boolean
    ): void
    {
        const hit = this.search.findHit(interactionEvent, displayObject, func, hitTest);

Which then calls _finishInteractionProcess

this._finishInteractionProcess(interactionEvent, func);

But _finishInteractionProcess expects func to exist, therefore fails:

_finishInteractionProcess(event: any, func: any)
    {
        const queue = this._queue;
        let q = queue[0];

        for (let i = 0, l = q.length; i < l; i++)
        {
            func(event, q[i], false);
        }

Uncaught TypeError: func is not a function
at LayersTreeSearch._finishInteractionProcess (DisplayMixin.ts:36)
at LayersTreeSearch.findHit (DisplayMixin.ts:36)
at InteractionManager2.processInteractive (InteractionManager.ts:1197)
at InteractionManager2.hitTest (InteractionManager.ts:790)

Environment

  • pixi.js version: 6.0.4

This started happening after I migrated to pixi 6.

@bigtimebuddy
Copy link
Contributor

Thanks for reporting this. Do you think you could do a minor reproduction? Would help us a lot to verify once we have a fix.

@soylomass
Copy link
Author

soylomass commented Jul 27, 2021

@bigtimebuddy

I'm quite busy right now, but I fixed it locally enclosing the func call inside an if. Has been working ok since then.

_finishInteractionProcess(event, func) {
    const queue = this._queue;
    let q = queue[0];
    **if (func) {**
        for (let i = 0, l = q.length; i < l; i++) {
            func(event, q[i], false);
        }
    **}**
    q = queue[1];
    for (let i = 0, l = q.length; i < l; i++) {
        if (!event.target) {
            event.target = q[i];
        }
        _if (func) {_
            func(event, q[i], true);
        _}_
    }
}

The bold if is the one I added. The italic if was already there.

EDIT: Bold and italic don't seem to work inside code. The one I added is the first if (func) {


PS: It's actually a pixi-layers problem. I can create the issue there if needed.

@bigtimebuddy bigtimebuddy transferred this issue from pixijs/pixijs Jul 27, 2021
@mhazy
Copy link

mhazy commented Sep 30, 2021

Duplicate of #69

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

3 participants