-
-
Notifications
You must be signed in to change notification settings - Fork 324
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
Throw exception in ViewportAdapter constructor if the GraphicsDevice is null #838
base: develop
Are you sure you want to change the base?
Throw exception in ViewportAdapter constructor if the GraphicsDevice is null #838
Conversation
Firstly, thank you for attention! It's a good idea, but why do you use the custom exception? There is People often use this way, so more easy to understand. |
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.
Thank you for the PR @safoster88
Please make the requested changes and then it can be merged.
public abstract class ViewportAdapter : IDisposable | ||
{ | ||
protected ViewportAdapter(GraphicsDevice graphicsDevice) | ||
{ | ||
if (graphicsDevice is null) | ||
{ | ||
throw new NullGraphicsDeviceException($"Attempted to construct {nameof(ViewportAdapter)} but {nameof(GraphicsDevice)} is null"); |
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 should just throw an ArgumentNullException
since the issue here is that the argument is null, not that the graphics device itself is null.
Please use the new method for checking
ArgumentNullException.ThrowIfNull(graphicsDevice);
{ | ||
var act = () => new TestViewportAdapter(null); | ||
|
||
Assert.Throws<NullGraphicsDeviceException>(act); |
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.
After making the suggested change of using ArgumentNullException
this should be updated to check for that exception type.
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 custom exception is not needed. The problem being solved is that the graphics device argument for the method is null, not that the GraphicsDevice itself is null. This can be removed and the exception changed to use ArgumentNullException
to better communicate to consumers that the argument being null is the issue.
If the viewport adapter is initialized in the constructor of game, GraphicsDevice will be null.
There is no check for this, so the null ref only occurs when trying to call GetViewMatrix().
This PR aims to improve the public API.