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

Mitigate null reference exceptions via better communication #8305

Open
tobskep opened this issue May 14, 2024 · 1 comment
Open

Mitigate null reference exceptions via better communication #8305

tobskep opened this issue May 14, 2024 · 1 comment

Comments

@tobskep
Copy link

tobskep commented May 14, 2024

Intent

Subscripting into collections should throw an exception if the member does not exist. For example, an Effect's collection of Techniques should raise an exception when a non-existent technique is subscripted. e.g.:

// i'm not very good at examples, sorry :(
var technique = e.Techniques["VertexLit"]; // no exception if technique exists
technique = e.Techniques["NonexistantTechnique"]; // raise exception if it doesn't

// helpful for many other things, too:
e.Parameters["WorldViewPosition"] = CalculateWVP();
e.Parameters["Blabla"] = "sixtyten"; // raise exception if parameter doesn't exist

Motivation

This would help mitigate the number of unhelpful NullReferenceExceptions thrown at the user which can be frustrating to debug and demoralizing. When these kinds of exceptions emerge, new users can feel as if MonoGame itself is broken, when really it's a tiny, easily missable detail of their own code which is very easy to pass up -- especially if it's worked in the past under other circumstances. .NET themselves acknowledge the annoying nature of the NullReferenceException, and I think it'd be beneficial if we limited the amount which the user has to deal with.

@stromkos
Copy link
Contributor

The Effects semantics/register allocation is completely separate from the C# code:

Build Time

The implementation of your feature would require parsing of the effect files, and all C# files in the project for consistency.

Run Time

The current implementation provides the best frame-rate possible. Would renaming the error grant anymore insight than the Call Stack at the cost of millisecond(s) per step?


Your post here alone will help others with the same problem.

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

No branches or pull requests

2 participants