Rework libpng error handling to catch version mismatch errors as well #134
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before 7e55228, there was an assert where even patch version jump caused the plugin to abort. Which happens pretty regularly, last with 1.6.38 -> 39, and is nothing that should be treated as a critical failure (I wonder what "libpng tutorial" was that taken from, sigh). The above-referenced commit removed this assert in order to unblock users, however it meant that a hypotetical upgrade from 1.6.x to 1.7 would cause the
png_create_{read,write}_struct()
to print for exampledirectly to the stdout (thus, impossible to see on e.g. Android), and then the plugin immediately does on
CORRADE_INTERNAL_ASSERT(png.file)
. This attempts to fix it properly.The
png_create_{read,write}_struct()
API accepts error/warning callbacks on its own, so supplying them there instead of inpng_set_error_fn()
allows it to direct the version mismatch error to us. Which is how itshould have been done in the first place (and again, I have no idea why the official libpng documentation doesn't show that, FFS).
Unfortunately, libpng directs the major/minor version mismatch fatal error to the warning callback, which is extremely confusing, and there's no way to detect and fixup the case apart from comparing the
string itself.
So that's what the first commit in this PR does. But then the changes cause a total breakage on clang-cl, and only there, with
longjmp
/setjmp
causing the program to jump somewhere totally insane, hitting assertions inDebug
destructor code paths that only ever get hit when!Debug
is used (which it isn't). Random ideas:https://en.cppreference.com/w/cpp/utility/program/longjmp says the following. The plugin attempts to have everything constructed before the first
longjmp
and destructed after the lastsetjmp
, but maybe not correctly?The following patch from @Squareys seems to make the test run again, however we don't yet understand why. I refuse to accept that the assertions, which may construct a
Debug
instance on stack, are what's causing problems -- that'd mean having to redesign the whole debug output printing...setjmp()
on its own inside the create function (to catch the version error and returnnullptr
), could this be the sole reason for everything catching fire? why is that a problem just for clang-cl?jmpbuf
because at the point wherelongjmp
is called from the version mismatch error,png.file
isn't filled in yet and thuspng_jmpbuf(file)
can't be called. But it makes no difference to the error on clang-cl.longjmp
. The only vaguely relevant bugs are:__builtin_setjmp
saves frame pointer incorrectly for x86_64-w64-windows-gnu (MinGW) target llvm/llvm-project#49486