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

camera.getPickRay exception when Scene is not rendered #10139

Merged
merged 13 commits into from
Feb 28, 2022

Conversation

srothst1
Copy link
Contributor

@srothst1 srothst1 commented Feb 24, 2022

The goal of this pull request is to address the issue with camera.getPickRay outlined in #10125

camera.getPickRay is currently throwing an exception that is not consistent with the rest of our Camera spec when Scene is not rendered. Based on the documentation (see pickEllipsoid, etc.) and various tests that I ran, pick operations are supposed to return undefined if the pick fails.

Currently, after the viewer is updated as follows:

viewer.scene.canvas.style.display = 'none';

I receive this error:

Uncaught DeveloperError: normalized result is not a number
Error
    at new DeveloperError (http://localhost:8080/Source/Core/DeveloperError.js:39:11)
    at Function.Cartesian3.normalize (http://localhost:8080/Source/Core/Cartesian3.js:422:11)
    at getPickRayPerspective (http://localhost:8080/Source/Scene/Camera.js:2922:14)
    at Camera.getPickRay (http://localhost:8080/Source/Scene/Camera.js:2994:12)
    at <anonymous>:7:37
    at HTMLButtonElement.button.onclick (http://localhost:8080/Apps/Sandcastle/Sandcastle-header.js:62:9) (on line 422 of http://localhost:8080/Source/Core/Cartesian3.js)

I am using this sandcastle demo for my testing.

A few lingering TODO items:

  • Update CHANGES.md
  • Update the Camera spec for getPickRay
  • Fix specs that I broke

@cesium-concierge
Copy link

cesium-concierge commented Feb 24, 2022

Thanks for the pull request @srothst1!

  • ❕ There was an error checking the CLA! If this is your first contribution, please send in a Contributor License Agreement.
    • Maintainers, this was the error I ran into while attempting to process the CLA check. Please resolve it to continue CLA checking.
    • You'll need to manually check for a submitted CLA
    Error: The service is currently unavailable.
    
  • CHANGES.md was not updated.
    • If this change updates the public API in any way, please add a bullet point to CHANGES.md.
  • ❔ Unit tests were not updated.
    • Make sure you've updated tests to reflect your changes, added tests for any new code, and ran the code coverage tool.

Reviewers, don't forget to make sure that:

  • Cesium Viewer works.
  • Works in 2D/CV.

@srothst1
Copy link
Contributor Author

The following updates have been made to Camera.prototype.getPickRay in Camera.js:

  • Added logic that checks if scene.canvas.style["display"] === "none"
  • If scene.canvas.style["display"] === "none", return undefined` given that the scene is not visible.
  • This seems more practical than calling getPickRayPerspective or getPickRayOrthographic, which yield runtime errors.

Copy link
Contributor

@ggetz ggetz left a comment

Choose a reason for hiding this comment

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

Thanks @srothst1 ! Before you get too deep in the specs, I have a suggestion about the approach here.

Source/Scene/Camera.js Outdated Show resolved Hide resolved
Source/Scene/Camera.js Show resolved Hide resolved
Source/Scene/Camera.js Outdated Show resolved Hide resolved
Source/Scene/Camera.js Outdated Show resolved Hide resolved
@srothst1
Copy link
Contributor Author

srothst1 commented Feb 25, 2022

Hi @ggetz. I am wondering if you have any feedback on the Travis CI build failures. When I run our specs using Jasmine on my local build, I seem to be getting various errors. These errors seem to occur even if I revert my branch back to 918c253, which had no issues when it was committed.

Edit: It seems like the last commit did not fail the Travic CI build. I suspect that the error was related to our above conversation.

Copy link
Contributor

@ggetz ggetz left a comment

Choose a reason for hiding this comment

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

Awesome, looking great @srothst1 ! I just have one small comment.

Specs/Scene/CameraSpec.js Outdated Show resolved Hide resolved
@ggetz
Copy link
Contributor

ggetz commented Feb 25, 2022

I suspect that the error was related to our #10139 (comment).

Yes, eslint was reporting an error and failing CI. You can check for eslint errors locally before you commit by running npm run eslint.

Co-authored-by: Gabby Getz <gabby@cesium.com>
@srothst1
Copy link
Contributor Author

Hi @ggetz. Please let me know if there is anything else that I need to take care of before this can be merged.

@ggetz
Copy link
Contributor

ggetz commented Feb 28, 2022

Looks good, thanks @srothst1 !

@ggetz ggetz merged commit c3e3451 into main Feb 28, 2022
@ggetz ggetz deleted the camera-PickRay-exception branch February 28, 2022 14:59
@mramato
Copy link
Contributor

mramato commented Feb 28, 2022

This is a breaking change and should probably be listed as such. getPickRay can now return undefined, which was not the case before.

@srothst1
Copy link
Contributor Author

@ggetz should I open up another PR that fixes CHANGES.md?

@ggetz
Copy link
Contributor

ggetz commented Feb 28, 2022

@mramato Even if those cases would have thrown a non-obviously related exception before?

@srothst1 If so, can you please open a PR to update CHANGES.md so that your bullet is under "Breaking changes"?

@srothst1
Copy link
Contributor Author

Hi @ggetz. Yes, I will open up another PR 👍

@mramato
Copy link
Contributor

mramato commented Feb 28, 2022

Even if those cases would have thrown a non-obviously related exception before?

Without TypeScript, I would agree with you, but with TypeScript, yes. The below TypeScript compiles fine with 1.90 but will fail with main after this PR.

let result: Ray;
const camera = new Camera(new Scene({ canvas: canvasElement }));
result = camera.getPickRay(new Cartesian2(0, 0));

With the error

Specs/TypeScript/index.ts:396:1 - error TS2322: Type 'Ray | undefined' is not assignable to type 'Ray'.

But more philosophically, changing a return type should always be documented as a breaking change because any code calling getPickRay must take into account that undefined is possible, and any code written against the previous documentation will not necessarily have done that.

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

Successfully merging this pull request may close these issues.

None yet

4 participants