floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
6.92k stars 487 forks source link

Crash on validation error #1009

Closed questor closed 6 months ago

questor commented 6 months ago

Hi! It would be great to have the option to crash the program on a validation error as I get error messages, but in a bigger project it's hard to find out where this is coming from (especially because the error message only prints the linenumber from the sokol-header and not from the point where it's called and in the last time there was a bigger change needed in the projects).

If I could crash the program I could easily get a callstack to look where it's coming from....

questor commented 6 months ago

ah, the concept is that you first scan all substructures and if in the original call something was bad you assert, right?

floooh commented 6 months ago

Yeah exactly, the validation layer 'batches' several validation checks (usually one batch per API call) and then 'panics' when any of the checks failed. Sometimes it's useful that the first detailed validation doesn't immediately crash because the later validation checks may add useful information, but sometimes it can also be confusing and a bit spammy.

In any case, a failed validation check ends up in the log callback with log level panic. If you hook your own log callback you could generate a callstack there.

Every detailed validation check also calls the log callback when it fails (with log level 'error' instead of 'panic'), and those also have the source file and line number in the log information. So by overriding the log callback you could extract quite a bit of "location information".