-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
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;
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. 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 |
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. |
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. |
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.