-
Notifications
You must be signed in to change notification settings - Fork 111
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
[RSDK-1035] Camera Properties call fails #1802
Conversation
if intrinsics := resp.IntrinsicParameters; intrinsics != nil { | ||
result.IntrinsicParams = &transform.PinholeCameraIntrinsics{ | ||
Width: int(intrinsics.WidthPx), | ||
Height: int(intrinsics.HeightPx), | ||
Fx: intrinsics.FocalXPx, | ||
Fy: intrinsics.FocalYPx, | ||
Ppx: intrinsics.CenterXPx, | ||
Ppy: intrinsics.CenterYPx, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the bug fix for the original issue. Here, if resp.IntrinsicParameters == nil
we would panic with the error
invalid memory address or nil pointer dereference
on line 171.
Checking if the resp.IntrinsicParameters == nil
before attempting to access its methods fixes the issue.
@@ -237,6 +237,104 @@ func TestClient(t *testing.T) { | |||
}) | |||
} | |||
|
|||
func TestClientProperties(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just tests we've fixed the bug and checks for similar issues.
@@ -204,3 +206,17 @@ func TestGetCameraMatrix(t *testing.T) { | |||
test.That(t, intrinsicsK.At(1, 2), test.ShouldEqual, intrinsics.Ppy) | |||
test.That(t, intrinsicsK.At(2, 2), test.ShouldEqual, 1) | |||
} | |||
|
|||
func TestNilIntrinsics(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a user gets back nil
intrinsic parameters (which is now possible thanks to my fix 😞) and attempts to call any of the methods below we'd panic. For example
props, err := cam.Properties(context.Background())
if err != nil {
logger.Fatal("attempting to get cam properties: %v", err)
return
}
props.GetCameraMatrix() // panic!
This is easily fixable by checking if the parameters are nil in these methods. It's also idiomatic to do this in Go AFAIK.
I noticed for the distortion parameters we have a struct transform.NoDistortion
that solves the same problem but I'm not sure what the advantage would be if we adopted that solution for intrinsic parameters too. Seems like they're both valid but I could be missing something. @bhaney it looks like you created that struct so if you have an opinion on this let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I think using nil as the "no intrinsics" and "no distortion" scenario is much more intuitive than creating a specific struct. Because then you have to remember to always use the "no such thing" struct, and nil is still there potentially causing problems!
3893928
to
37536a9
Compare
@bhaney removed NoDistortion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have just one fix for the panic test, otherwise LGTM!
// NoneDistortionType applies no distortion to an input image. Essentially an identity transform. | ||
NoneDistortionType = DistortionType("no_distortion") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for getting rid of this, making "no distortion" just be nil is much simpler
@@ -204,3 +206,17 @@ func TestGetCameraMatrix(t *testing.T) { | |||
test.That(t, intrinsicsK.At(1, 2), test.ShouldEqual, intrinsics.Ppy) | |||
test.That(t, intrinsicsK.At(2, 2), test.ShouldEqual, 1) | |||
} | |||
|
|||
func TestNilIntrinsics(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I think using nil as the "no intrinsics" and "no distortion" scenario is much more intuitive than creating a specific struct. Because then you have to remember to always use the "no such thing" struct, and nil is still there potentially causing problems!
nilIntrinsics.CheckValid() | ||
nilIntrinsics.GetCameraMatrix() | ||
nilIntrinsics.PixelToPoint(0.0, 0.0, 0.0) | ||
nilIntrinsics.PointToPixel(0.0, 0.0, 0.0) | ||
nilIntrinsics.ImagePointTo3DPoint(image.Point{}, rimage.Depth(0)) | ||
nilIntrinsics.RGBDToPointCloud(&rimage.Image{}, &rimage.DepthMap{}) | ||
nilIntrinsics.PointCloudToRGBD(pointcloud.PointCloud(nil)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use test.ShouldNotPanic so that it doesn't actually panic and cause the testing program to crash
You need to wrap them each in a function i.e.
test.That(t, func() { nilIntrinsics.CheckValid() }, test.ShouldNotPanic)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, fancy! Done.
5172a18
to
6f973a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, sorry for the delay!
Note: merge base coverage results not available, comparing against closest aa1914d~2=(9e2f63d) instead
|
Bug fix: See script in RSDK-1035 for steps to reproduce.