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

Mesh: Prevent infinite loop in raycast(). #22068

Merged
merged 1 commit into from
Aug 30, 2021

Conversation

artificial-jon
Copy link
Contributor

Description

If you raycast at a Mesh with multiple materials, you end up in an infinite loop if both group.count and drawRange.count are set to Infinity. (Which seems to me to be a common case.) The single material cases check against the minimum of index.count or position.count (depending on if the Geometry is indexed or not). It seems to me that this same check should be included in the array of materials case as well.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 1, 2021

(Which seems to me to be a common case.)

I'm afraid that's not. When defining groups, you normally define a discrete range (which is not open up).

Do you mind explaining in more detail how your group data are defined? You can modify the following fiddle (multimaterial setup with raycasting) for demonstration: https://jsfiddle.net/d7gjxqsm/

@WestLangley
Copy link
Collaborator

When defining groups, you normally define a discrete range

Other patterns are supported, and used: #12135 (comment)

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 1, 2021

I'm aware of that but it is not the common case^^.

@artificial-jon
Copy link
Contributor Author

The example from @WestLangley is exactly what I was doing. I added multiple groups from 0 - Infinity so that I could apply multiple materials to a single mesh. If you raycast at that mesh, your app will hang.

I defer to @Mugen87 regarding how common it is. :)

I can modify the fiddle later today if it is still useful.

@artificial-jon
Copy link
Contributor Author

Here is a fiddle to show the problem. It is basically the pattern from @WestLangley applied to the fiddle from @Mugen87 .
https://jsfiddle.net/jfournie/xmqh5vwe/22/

In order to enable the bug, uncomment the raycaster.intersectObjects() line near the bottom. For me, this puts my browser in a really unhappy state.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 1, 2021

After all I'm not super happy we the entire groups/multi material implementation. Hopefully we can left it out in WebGPURenderer and just focus on a single material per object,

@Mugen87 Mugen87 added this to the r131 milestone Jul 8, 2021
@mrdoob mrdoob modified the milestones: r131, r132 Jul 28, 2021
@mrdoob mrdoob modified the milestones: r132, r133 Aug 26, 2021
@Mugen87
Copy link
Collaborator

Mugen87 commented Aug 30, 2021

@mrdoob This PR is good to go.

@Mugen87 Mugen87 changed the title Prevent infinite loop in Mesh.raycast(). Mesh: Prevent infinite loop in raycast(). Aug 30, 2021
@mrdoob mrdoob merged commit 595987e into mrdoob:dev Aug 30, 2021
@mrdoob
Copy link
Owner

mrdoob commented Aug 30, 2021

Thanks!

@artificial-jon artificial-jon deleted the raycastInfinteLoop branch October 18, 2021 21:56
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

Successfully merging this pull request may close these issues.

4 participants