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

Fix NullPointer in MikktspaceTangentGenerator #2338

Merged
merged 5 commits into from
Jan 6, 2025

Conversation

yaRnMcDonuts
Copy link
Member

Fixes a null pointer exception that occurred when trying to generate tangents on a model without a normal buffer: https://hub.jmonkeyengine.org/t/mikktspacetangentgenerator-fails-with-npe/48114/4

This PR makes it so that MikktspaceTangentGenerator handles a non existant normal (or texCoord) buffer in the same way that the old TangentBinormalGenerator handled it.

Fixes a null pointer exception that occurred when trying to generate tangents on a model without a normal buffer: https://hub.jmonkeyengine.org/t/mikktspacetangentgenerator-fails-with-npe/48114/4

This PR makes it so that MikktspaceTangentGenerator handles a non existant normal (or texCoord) buffer in the same way that the old TangentBinormalGenerator handled it.
forgot to add import for VertexBuffer.Type;
@yaRnMcDonuts yaRnMcDonuts added this to the v3.8.0 milestone Dec 29, 2024
@MeFisto94
Copy link
Member

MeFisto94 commented Dec 29, 2024

Did you guys discuss how error-feedbacky you want this method to be? Because for me, there's opportunity in changing behavior, albeit implicitly, which is usually a hard no for APIs, but:

On one hand, there's the Exception for not supported mesh types, but things like Lines are silently ignored, too.
Personally, the requirement of generating tangents for meshes that don't have a normal map feels illegal/unsupported, so throwing would be fine. It's not what we expect to do. But then we should do the same for Lines.

This could probably be shifted to user-code if we had the main Method take a Geometry (or even Mesh!) and only keep the Spatial method as convenience/deprecate it and then having the user be responsible to not try to generate nonsense.

The risk with being fault tolerant is always that faults fly under the radar, so we could/should at least emit a warning in these cases

@yaRnMcDonuts
Copy link
Member Author

yaRnMcDonuts commented Dec 30, 2024

there's opportunity in changing behavior, albeit implicitly, which is usually a hard no for APIs

I personally was aiming to avoid this, since I have very little understanding of this class, especially the math behind it. So I wanted to make the PR as minimal as possible, and to follow the same approach that TangentBinormalGenerator took (which also just silently ignores meshes without normals)

The main goal of this PR is just to fix the crashing NPE that occurred when another jme user tried generating tangents on a model that had some meshes with normals and some without. So ideally we should fix it so they don't have to go through manually and determine which meshes are valid and then have to generate tangents one mesh a time. It is important that generating tangents on a parentNode handles the generation of all children safely and error free, even in cases where a child mesh has no normals.

But I'd say it would be okay to add some code this PR to make MikktSpaceTangentGenerator output a simple warning or message of some sort whenever a mesh without normals/triangles/texCoords is detected. However there is also the argument that adding more (potentially unecssary) warning clutters up the console output. And the TangentBinormalGenerator has worked fine with no extra warning being output when a mesh is ignored. I think most users would not have an issue if a model with no normals gets no tangents and I wouldn't say that is something wrong or out of the ordinary that is worthy of a warning. I'd say that everything is just working as expected in this scenario.

@yaRnMcDonuts
Copy link
Member Author

There was another PR related to some fixes to MikktSpaceTangentGenerator that required me to look at the code some more, so I went ahead and added the suggested loggign output in case of no triangle or no buffers, and removed some other redundant logging that would've been there twice after having merged that other PR.

Unless anyone has issues with the changes, I'll merge this in the next day or two.

@yaRnMcDonuts yaRnMcDonuts merged commit f90188e into master Jan 6, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants