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

Fix clipping planes crash when adding plane to empty collection #7168

Merged
merged 4 commits into from
Oct 26, 2018
Merged

Fix clipping planes crash when adding plane to empty collection #7168

merged 4 commits into from
Oct 26, 2018

Conversation

OmarShehata
Copy link
Contributor

This fixes #7167.

The problem was, if there are no clipping planes added, the width is 0, and height is 1/width, hence the NaN crash.

I fixed it by only creating the texture when it needs to. I also added 2 tests that would have caught this/to make sure it doesn't happen again.

@lilleyse can you review? Here are all your Sandcastle links as localhost links to confirm it doesn't crash now:

Model
3D Tiles
Terrain
Point clouds

@cesium-concierge
Copy link

cesium-concierge commented Oct 18, 2018

Thanks for the pull request @OmarShehata!

  • ✔️ Signed CLA found.
  • CHANGES.md was not updated.
    • If this change updates the public API in any way, please add a bullet point to CHANGES.md.

Reviewers, don't forget to make sure that:

  • Cesium Viewer works.
  • Works in 2D/CV.
  • Works (or fails gracefully) in IE11.

I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome.

🌍 🌎 🌏

@likangning93
Copy link
Contributor

This was true in master as well, but it looks like removing all planes leads to a crash. I tweaked the Many Clipping Planes Sandcastle example, here on localhost:8080.

@OmarShehata
Copy link
Contributor Author

Thanks for the additional test case @likangning93 . Looks like the problem was a little more subtle. There's a lot of assumptions in the clipping plane code that there will always be at least 1 plane. So, it's not that it crashes when you add planes and remove them all, it will always crash if there aren't any planes, it's just that Model.js doesn't update the first time when there aren't any planes.

I made some broader changes now, that clipping planes should be only be applied if there's at least one plane. I think this is a better solution than passing an empty texture and running the shader.

Would you like to review this Gary?

Copy link
Contributor

@likangning93 likangning93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one note that doesn't actually need changes, otherwise this looks good. Can you update CHANGES.md?

@@ -145,7 +145,7 @@ define([
(imageryCutoutFlag << 21);

var currentClippingShaderState = 0;
if (defined(clippingPlanes)) {
if (defined(clippingPlanes) && clippingPlanes.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the clippingPlanes.length > 0 check is covered in GlobeSurfaceTileProvider.computeTileVisibility by a check for if the globe surface tile intersects any clipping planes. We also do this for 3D Tiles, so tiles in a tileset that aren't touched by any clipping planes won't have injected clipping code. This change doesn't seem like it will hurt beyond being a little inconsistent with what's happening elsewhere, so no change needed, just wanted you to be aware.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might not be needed here, but Model was crashing because it considered clipping planes enabled even if there weren't any, so I added this check everywhere else to be consistent.

@OmarShehata
Copy link
Contributor Author

Should be ready now @likangning93 !

@likangning93
Copy link
Contributor

CI still refusing to run tests for unknown reasons, but they pass locally using the same commands and I don't see anything in here that would be causing the CI failure. I'm going to merge, noted in #7193.

@likangning93 likangning93 merged commit ff3db12 into CesiumGS:master Oct 26, 2018
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.

Crash after adding clipping plane to empty clipping plane collection
3 participants