ciolib-win32-gdi divide by zero crash in 43-line/EGA mode (run with '-l43' command-line option)
Unhandled exception at 0x005BCADF in scfg.exe: 0xC000041D: An unhandled exception was encountered during a user callback.
Problem/crash does not happen 100% of the time.
The line of code in scale.c where the exception occurs is
// If x/y scaling isn't a simple multiple, block scale everything...
if ((total_yscaling % total_xscaling) == 0) {
total_xscaling 0 int
total_yscaling 1 int
Backtrace:
scfg.exe!do_scale(rectlist * rect, int fwidth, int fheight) Line 249
at c:\sbbs\src\conio\scale.c(249)
scfg.exe!gdi_handle_wm_paint(HWND__ * hwnd) Line 296
at c:\sbbs\src\conio\win32gdi.c(296)
scfg.exe!gdi_WndProc(HWND__ * hwnd, unsigned int msg, unsigned int wParam, long lParam) Line 579
at c:\sbbs\src\conio\win32gdi.c(579)
[External Code]
[Frames below may be incorrect and/or missing, no symbols loaded for user32.dll]
scfg.exe!gdi_thread(void * arg) Line 874
at c:\sbbs\src\conio\win32gdi.c(874)
scfg.exe!invoke_thread_procedure(void(*)(void *) procedure, void * const context) Line 82
at d:\th\minkernel\crts\ucrt\src\appcrt\startup\thread.cpp(82)
scfg.exe!thread_start<void (__cdecl*)(void *)>(void * const parameter) Line 115
at d:\th\minkernel\crts\ucrt\src\appcrt\startup\thread.cpp(115)
[External Code]
scfg.exe!__crt_stdio_input::input_processor<wchar_t,__crt_stdio_input::string_input_adapter<wchar_t>>::process_state() Line 1122
at d:\th\minkernel\crts\ucrt\inc\corecrt_internal_stdio_input.h(1122)
Stepping through the code, I see this calculation:
int yscale = fheight / rect->rect.height;
Results in yscale = 0 (350 / 400).
And then in the if (xscale > yscale) {
block, the yscale
value (0) is assigned to xscale
which is then later assigned to total_xscaling
.
Why this problem doesn't happen 100% of the time, I don't know. Perhaps the rect
object is shared with another thread?
When it doesn't crash, the fheight
parameter value is 400, so yscale
is assigned 1 and no divide by zero happens.