-
Notifications
You must be signed in to change notification settings - Fork 135
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
Improved error output #169
Comments
I think this is a good thing to discuss, and it's worth mentioning that the Filament client deals with this by calling cgltf_validate in its debug build, which provides reasonable feedback when CGLTF_VALIDATE_ENABLE_ASSERTS is enabled. |
My 2 cents would be that it's only meaningful with human-readable error output if the user can reasonably be expected to fix the error. If the glTF is referring to a missing external file or runs out of memory while processing - fine. If the JSON is malformed or there is a data integrity issue, I'm less sure. Isn't it better if the user reports the issue to the exporting application devs then? |
I believe it would be great to have better error reporting! I'd also love it to be optional. 👍 @pezcode Would @LxLasso Generally, you're right. But you may still have expert users who just want to find out what's wrong with their glTF file and fix it. Error messages could very well help in that case. Maybe you don't have to throw the error at everyone, but hide them behind some "more details" button. Also, the file might not come from some proper exporting application, but it might be generated or hand-crafted even. Or maybe someone is writing a new exporter and would like help from cgltf to get it up and running? |
Fair enough, I've been there myself. I used https://github.khronos.org/glTF-Validator/ then though. |
The cases we've been running into with @pezcode (in Magnum's cgltf-based importer) were mostly due to various syntax or out-of-bounds errors, which caused the initial But of course because cgltf uses pointers for references to meshes etc. (and not indices like for example tiny_gltf), it has to do this checking during the initial parsing already, there's no way around that. It would just be great to get more context for the error state. Optionally of course, I'm well aware of the use cases where binary size matters most. As @jkuhlmann says, we fall into the "expert users" category where we hand-craft or generate glTFs ourselves and having to use an external validator every time cgltf says "nah" is a productivity killer :) As far as I can see, these are the main cases:
Regarding Huh, sorry for such a lengthy post. The TL;DR variant of it is that the initial version of this would only need a few tiny changes with no negative impact for existing users or maintainers -- a couple of |
In general, I like the approach. There are two things, however, that I think could use a little more work:
Do you think it would make sense to keep the functionality in the macros and instead just let the user add the error handling? Something like this: #define CGLTF_REPORT_ERROR_PTRFIXUP(var, data, size) \
printError("Index {} out of bounds for {} {}", \
var - 1, size, #data + sizeof("data->") - 1); \
#ifndef CGLTF_REPORT_ERROR_PTRFIXUP
#define CGLTF_REPORT_ERROR_PTRFIXUP(var, data, size)
#endif
#define CGLTF_PTRFIXUP(var, data, size) \
if (var) { \
if ((cgltf_size)var > size) { \
CGLTF_REPORT_ERROR_PTRFIXUP(var, data, size); \
return CGLTF_ERROR_JSON; \
} \
var = &data[(cgltf_size)var-1]; \
} |
Yes, that would be even better, good idea :) I was just trying to come up with a minimally invasive change that would enable us to do what we need. But you have a valid point in that it'd make the overrides rather brittle and cgltf's internals harder to read. Should I then prepare a PR with changes that follow your suggestion? |
That would be great and very much appreciated! |
Just FYI, and sorry for the very late comment -- as our use case ended up diverging even further from cgltf's goals, we ended up making our own parser from scratch. Thus we no longer have a need for the changes proposed here, and I'm afraid I won't find time to PR the implementation. Feel free to close the issue. Thanks for all your work nevertheless -- cgltf made us realize that efficient glTF parsers can exist :) |
👋
cgltf error output is rather minimal, which can be an issue for user-facing glTF importing. 95% of broken files out there end up with a non-descriptive "invalid glTF" without any more context.
I'm mostly hoping to get a discussion started in this issue. How to improve human-readable error output without unnecessarily complicating or slowing down cgltf?
A non-exhaustive list of possible changes:
CGLTF_ERROR
macro that takes a string literal. By default does nothing, so the literal should be compiled away. Either letting the user override the macro and handle the error string, or store it incgltf_data
if some preprocessor define is set. Needs a bit of work to retrospectively add error messages everywhere, so could be made optional.CGLTF_PTRFIXUP_REQ
overridable so you can print somewhat useful errors like "data->textures[i].image (7) out of bounds for data->images (size 6)"cgltf_data
or an optional parameter to thecgltf_parse
functionsI'd love to get some feedback on this, anything from "not needed" to concrete ideas. We're certainly willing to contribute work towards a PR since this has become a bit of a pain point.
The text was updated successfully, but these errors were encountered: