The new LRGB->RGB conversion is in speed comparable to array lookup,
so instead of precomputing the palette and then looking up values, just
recompute the conversion for each pixel.
Turns out the rescaling expression can be expressed in form A*x+B
followed by bitshift for all 217 possible values of x. And while at
it, use templates to merge most of the locolor/hicolor conversion
functions.
Leave globalwrap state as uninitialized, even if that causes a compile
warning as initializing breaks AVI dumping on Windows. All globalwraps
should have static storage duration anyway, and C++ can not have
uninitialized variables with static storage duration.
Turns out there are three copies of LRGB->RGB routine (two 8-bit and one
16-bit). Merge the 8-bit ones and remove L+1 causing L=0 to be not fully
black. Fixes fade afterimages in Super Mario World.
Turns out nothing was setting the prev pointer on doubly linked list when
creating callback nodes, so Lua GC'ing any node from the middle corrupted
the list, leading to unregister* intermittently failing to actually
unregister the callback.
If callback is executing, its callback handle must not be freed as freeing
it would trigger UAF. So if currently running callback is unregistered,
delay freeing the handle until the callback finishes running.
Turns out that if Lua throws e.g. a table as error, tostring (and
tolstring) returns NULL. And trying to print NULL into message stream
causes it to hang). Guard against tolstring returning NULL, and print
(null) instead of trying to print the NULL pointer.
If one tries to open a setting window, the emulator grabs the input.
However, if opening the window then fails (most commonly because it is
joystick settings window, and there are no online nor offline gamepads)
the grab needs to be undone because otherwise the grab will point to
freed memory. The destructor would undo it, except failure to open window
triggers exit from constructor by exception, in which case destructor
will not run.
Bug reported on IRC.
Not all warnings were squashed, some seem impossible to sanely fix,
e.g. warnings about not using some function that is used in another
compilation unit, or C++17 changing name mangling of some things.
- Fix uninitialized closed flag in avi_worker
- Fix uninitialized stream parameters in avi_writer
- Fix stack smash in AVI write_pkt (the padding is only 2 bytes, don't
write an u32 into it!)
Turns out framebuffer draw recalibrates mouse_x and mouse_y, which then
calls into hook. Which is no-no, because framebuffer draw runs in GUI
thread, and hooks must run in game thread.