From caaa08be0799d4bd9f393b5c8ba80c808e30cbd6 Mon Sep 17 00:00:00 2001 From: Eric Jensen Date: Sat, 7 May 2016 01:49:22 +0200 Subject: [PATCH] Disable optimizations in wxQuantize() for MSVC to avoid crash Compiler seems to generate incorrect code for the dithering code taken from libjpeg, where it is known to create problems too, so use the same workaround as libjpeg uses and disable optimizations for this function. This is unsatisfactory and it would be great to find a way to tweak the code to avoid the problem, but it's still better than crashing. See #17764. --- src/common/quantize.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/common/quantize.cpp b/src/common/quantize.cpp index 4fa2988ca4..044314e447 100644 --- a/src/common/quantize.cpp +++ b/src/common/quantize.cpp @@ -1026,6 +1026,16 @@ pass2_no_dither (j_decompress_ptr cinfo, } } +#ifdef __VISUALC__ +/* + for (yet) unknown reasons, the following code produces + bad results or even crashes if the code optimization is + enabled in VC++ + + disable optimization for now until the reason is discovered +*/ + #pragma optimize ("", off) +#endif void pass2_fs_dither (j_decompress_ptr cinfo, @@ -1167,7 +1177,9 @@ pass2_fs_dither (j_decompress_ptr cinfo, errorptr[2] = (FSERROR) bpreverr2; } } - +#ifdef __VISUALC__ + #pragma optimize ("", on) +#endif /* * Initialize the error-limiting transfer function (lookup table).