I have a Xamarin Forms app which is applying 3D rotation to a view. On some devices the default perspective looks really bad so I had to create a custom renderer so that I could specify the camera distance for the view. All of the examples I have seen suggest setting the distance based on the "Resources.DisplayMetrics.Density" value. I got this to work, but for some reason it seems I have to set it repeatedly. Sometimes in the course of grabbing this value I was getting an Exception - usually after backgrounding and foregrounding the app. This is the error:
System.ArgumentException has been thrown
'jobject' must not be IntPtr.Zero.
In the code below the Exception is called on the line where I check whether or not Resources is null. Is there a workaround for this? How can I verify that Resources is "safe" to touch?
`void OnUpdateCamera ()
if (Resources == null)
int distance = 2500; float scale = Resources.DisplayMetrics.Density; SetCameraDistance (distance * scale);