Commit 4d6affd74d ("Fix SDL-only briefing crash") added a hack to
prevent a crash when the briefing window is automatically resized.
However, a logic error in that hack causes some subcanvases that were
not wrong to be truncated. Change the logic to fix those subcanvases,
such as the one used for rendering a background in the High Scores
window. The new logic still avoids the crash in in SDL-only mode.
Fixes: 4d6affd74d ("Fix SDL-only briefing crash")
Trim the bitmap's current width and height to be not more than its
parent. Otherwise, an automatic screen resize, such as triggered when
playing the robot briefings in Descent 2, will give the window a new
smaller bm_data, but continue to use the old dimensions. This then
causes load_briefing_screen -> gr_bitmap_scale_to -> scale_line to write
off the end of the smaller bm_data, causing memory corruption and
eventually a crash.
- Add a limiter to let it return early when the result is predictable.
The first caller checks only whether the returned value is above a
threshold. Once the value goes above that threshold, its precise
value will not matter, so stop counting and return early.
- Add comments explaining some of the logic.
gr_init_bitmap can be passed a pointer to uninitialized memory, and
will save that pointer into the bitmap for the underlying memory to be
initialized later. In gcc-11, this triggers a warning because the
`const` qualifier leads gcc to expect that the memory will only be read
(while uninitialized) and not written.
Reported-by: TheDemonicSurfer <https://github.com/dxx-rebirth/dxx-rebirth/issues/593>
Utility xrange, inspired by the Python2 feature of the same name,
provides an object that returns successive values from [start, end). It
is useful when the end index is known in advance, and is particularly
helpful when that index is expensive to recompute.
Bitmaps based on grs_main_bitmap own their data. Bitmaps based on
grs_bitmap do not. Adjust prototypes to prevent initializing a
grs_main_bitmap with data it will not own.
For each link given as http://, verify that the site is accessible over
https:// and, if so, switch to it. These domains were converted:
* llvm.org
* clang.llvm.org
* en.cppreference.com
* www.dxx-rebirth.com
* www.libsdl.org
* www.scons.org
`build_colormap_good` only took `used` to clear it. Only one caller
needed it cleared. Move the clear into that caller. Remove the
parameter from all calls.
Both the `if` and `else` paths had the same loop and post-loop
processing. The `if` path was a strict subset of the `else` path. The
`else` path had one setup statement, and was otherwise equal to the `if`
path. Move the shared statements outside the guarded path.