If music is configured as built-in, and no secret songs are configured,
then BIMSecretSongs is set to a non-null pointer to a zero-element
array. This triggers a divide-by-zero when the array length is used in
a modulus operation.
Fix this by adding a special case that initializing from an empty vector
calls `reset()`, which causes the underlying unique_ptr to store
`nullptr` instead of `new bim_song_info[0]`.
Reported-by: Daniel-Leontiev <https://github.com/dxx-rebirth/dxx-rebirth/issues/465>
Fixes: c355e207fe ("Refactor song loading")
Descent 2 has a hack, present as far back as I can trace, that
suppresses starting sounds during level load. The original reason was
not recorded, but this hack has the useful side effect that it avoids
using uninitialized data when set_sound_sources tries to use a Viewer
that has not been reset for the objects of the new level.
Descent 1 lacks this hack, so an invalid Viewer is used, which may
trigger a valptridx trap if the undefined data has an invalid segment
number, and could cause memory corruption in builds which do not
validate the segment index. The valptridx trap:
```
terminate called after throwing an instance of 'valptridx<dcx::segment>::index_range_exception'
what(): similar/main/digiobj.cpp:389: invalid index used in array subscript: base=(nil) size=9000 index=65021
```
The backtrace leading to the trap:
```
d1x::digi_link_sound_common (viewer=..., so=..., pos=..., forever=<optimized out>, max_volume=<optimized out>, max_distance=..., soundnum=42, segnum=...) at similar/main/digiobj.cpp:389
0x00005555555a4e2d in d1x::digi_link_sound_to_pos2 (vcobjptr=..., max_distance=..., max_volume=32768, forever=1, pos=..., sidenum=4, segnum=..., org_soundnum=121) at similar/main/digiobj.cpp:483
d1x::digi_link_sound_to_pos (soundnum=soundnum@entry=121, segnum=..., sidenum=sidenum@entry=4, pos=..., forever=forever@entry=1, max_volume=32768) at similar/main/digiobj.cpp:490
0x00005555555c140d in d1x::set_sound_sources (vcsegptridx=..., vcvertptr=...) at similar/main/gameseq.cpp:817
d1x::LoadLevel (level_num=<optimized out>, page_in_textures=1) at similar/main/gameseq.cpp:1022
0x00005555555c2654 in d1x::StartNewLevelSub (level_num=-1, page_in_textures=<optimized out>) at similar/main/gameseq.cpp:1865
```
Backport this hack into Descent 1. Ultimately, the hack should go away
and data should be loaded in an order that does not access undefined
memory.
Reported-by: Spacecpp <https://github.com/dxx-rebirth/dxx-rebirth/issues/463>
clang-9 reports:
```
similar/main/mglobal.cpp:210:44: error: 'report_error_uses_exception' is a protected member of 'valptridx_specialized_type_parameters<unsigned char, 90, valptridx_untyped_utilities::report_error_style::exception, valptridx_untyped_utilities::report_error_style::exception>'
template <typename T, bool = valptridx<T>::report_error_uses_exception::value>
^
similar/main/mglobal.cpp:229:16: note: in instantiation of default argument for 'instantiation_guard<dcx::active_door>' required here
template class instantiation_guard<dcx::active_door>::type::index_range_exception;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
common/include/fwd-valptridx.h:42:2: note: constrained by protected inheritance here
protected valptridx_specialized_types<managed_type>::type
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
common/include/cpp-valptridx.h:175:8: note: member is declared here
using report_error_uses_exception = std::integral_constant<bool,
```
Add a `using` statement to switch `report_error_uses_exception` to
`public` access. Nothing else uses it, and there is no design purpose
served by keeping it `protected`.
clang searches for its installed headers relative to the path of the
program calling it, which doesn't work when the caller is a custom
program running from directory other than the system clang installation
directory. Add a hook to the compilation database support to let the
user inject extra flags into the database, which can be used to add
`-isystem $PATH_TO_INSTALLED_CLANG_HEADERS` to the recorded commands, so
that when the clang library loads the compilation database, it finds the
headers.
Commit 0df57f5b0f changed markers' movement type from MT_NONE to
MT_SPINNING, since retail code assigned a spin rate, suggesting markers
were meant to spin. However, in some anarchy games, markers are used as
player-positioned cameras. Spinning the cameras makes them hard to use.
Resolve this by preventing markers from spinning in such games.
Fixes: 0df57f5b0f ("Fix retail bug that prevented marker spinning")
Reported-by: flpduarte <https://github.com/dxx-rebirth/dxx-rebirth/issues/456>
psyke83 reports that Raspbian Buster with gcc 8.3.0 rejects the
`-isystem=dir` form. The `=dir` form does not work on any gcc I can
test, so conditionally keeping it for other systems does not seem
worthwhile.
Requested-by: psyke83 <https://github.com/dxx-rebirth/dxx-rebirth/pull/453>
Commit 452d58a0b5 switched from passing a list of strings as the
right-hand side of `in` to passing a parenthesized string. The new form
causes a TypeError if the left hand side is None:
```
>>> None in ('1', '2')
False
>>> None in ('1')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'in <string>' requires string as left operand, not NoneType
```
Add a trailing comma to turn the right hand side back into a list of
strings, as it was before the Raspberry Pi commit.
Fixes: 452d58a0b5 ("Update Raspberry Pi Mesa build for Buster & Pi 4B")
The new Raspberry Pi 4B revision has a minimum requirement of Raspbian
buster, and uses the Mesa V3D driver by default; in fact, the legacy
Broadcom drivers are no longer compatible with its VideoCore VC6 chip, so
building against Mesa is mandatory for this Pi revision.
Unfortunately, the Debian buster version of the Mesa packages
have intentionally dropped the GLESv1 headers, making building of GLESv1
software impractical (even though the VC4/V3D driver can still run GLESv1
applications).
The OpenGL driver in conjunction with SDL2* runs at full
speed on Raspberry Pi 3B & 4B, so it makes sense to modify the "mesa"
build to this configuration in light of these facts.
* SDL2 is highly desirable due to the availability of the KMSDRM driver, which is
the only way to run dxx-rebirth outside of X (we can no longer use
the dispmanx/rpi driver of SDL1).
When targeting Raspberry Pi with legacy drivers, the following error
is observed on Raspbian buster with gcc 8.3.0:
cc1plus: error: =/opt/vc/include: No such file or directory [-Werror=missing-include-dirs]
cc1plus: error: =/opt/vc/include/interface/vcos/pthreads: No such file or directory [-Werror=missing-include-dirs]
cc1plus: error: =/opt/vc/include/interface/vmcs_host/linux: No such file or directory [-Werror=missing-include-dirs]
The error can be resolved by removing the equals sign from these definitions.
On all platforms, libSDL redefined `main` in a way that interfered with
SConf tests. On some platforms, but not on Linux, libSDL2 does not
redefine `main`. Based on a remark in the SDL2 migration guide, and the
apparent success (on Linux) after removing the `#undef`, I removed use
of `#undef` when building for SDL2. As privately reported by zico,
libSDL2 on Windows still redefines `main`, so it still needs an explicit
`#undef` to let the SConf tests build correctly. For platforms where
`#undef` is not needed, it is harmless. Add this `#undef`
unconditionally, and update the inline comment.
Fixes: f491059ed7 ("Enable building with SDL2")
Reported-by: zicodxx <private>
Each axis can act as two buttons in both ways.
For example, a player might map slide left and slide right to J1 -A1 and J1 +A1 as button presses instead of the slide L/R axis.
This is mostly to fix XBox 360 Controller Left and Right triggers. But it can work on every axis if the player wishes to bind them.
Defer decreasing energy/vulcan until the object is confirmed to be
created. This avoids charging the player for a shot that cannot be
created due to object exhaustion.
Defer updating Next_laser_fire_time, so that a player can immediately
try firing again.
Defer decreasing energy (for flares) or secondary weapon count (for
secondaries) until the object is confirmed to be created. This avoids
charging the player for a shot that cannot be created due to object
exhaustion.
Otherwise, unless FrameTime exceeds Final_boss_countdown_time in a
single frame, the time never advances and the level never ends.
Fixes: 215252b8ca ("Fold Final_boss_is_dead into Final_boss_countdown_time")
The prior commit fixed the problem of a blank pilot name for new games,
but loading an existing save game uses a different path and still did
not set the player's callsign. Set it on load, too.
Fixes: 0c7de10512 ("Track chosen pilot name outside Players[]")
Single player games relied on the quirk that the pilot's name was always
kept in Players[], even outside a game. Commit 0c7de10512 removed
that quirk, which had the unintended consequence that single player
games are now played by the anonymous pilot. Set the player's callsign
during game setup so that the high score entry can be attributed
correctly.
Fixes: 0c7de10512 ("Track chosen pilot name outside Players[]")
Reported-by: Neurochild247 <https://github.com/dxx-rebirth/dxx-rebirth/issues/443>
Bisected-by: zicodxx <https://github.com/dxx-rebirth/dxx-rebirth/issues/443#issuecomment-523827234>
Commit e6169f17f9 switched from searching `Data/` to searching
`data/`. For users on case-insensitive filesystems, this is a no-op and
the instructions that reference the `Data` directory continue to work.
For users on case-sensitive filesystems, the change broke accessing the
data directory, and caused the instructions to mislead. Given the age
of the commit, fixing the capitalization now will likely cause more
problems than it solves. Instead, fix the capitalization of the
instructions, so that users who follow the documentation get a working
setup.
Reported-by: krux02 <https://github.com/dxx-rebirth/dxx-rebirth/issues/447>
Fixes: e6169f17f9 ("Add 'Data' subdir as a searchpath, so D2X will find descent.pig and to simplify a lot of file opening/checking/closing code")
If the level was not the most recently played, a save is forced so that
it can be marked as most recently played. However, the logic to force
the save also forced an update of the highest-level field, even if that
reduced it.
- Rename the parameter to clarify its meaning.
- Add comments explaining the logic to force the save.
- Only update the highest-level field when the update would increase the saved value
If a guided missile is in flight, and its owning player dies, the
player's type is changed to OBJ_GHOST. The damage that killed the
player should have put the guided missile into autonomous mode, so for
this purpose, return that the missile is not actively guided.
Reported-by: Johnsondr80 <https://github.com/dxx-rebirth/dxx-rebirth/issues/437>
The subcanvas is positioned based on the dimensions of the containing
window, so it must be repositioned if the outer window is resized.
Reported-by: vLKp <https://github.com/dxx-rebirth/dxx-rebirth/issues/394>
Fixes: f491059ed7 ("Enable building with SDL2")
exit_segnum is set during load_endlevel_data, which currently runs too
early for this to depend on the exit used, and thus to be player-unique.
That data should be loaded at need, when the level ends, rather than
during level setup. This can be addressed later, when support for
multiple exits is improved.
transition_segnum is a function of how the player exited the mine, since
there could be multiple exit tunnels, although current code appears not
to handle that well in other places. Therefore, it needs to be
per-player data, not part of the level data, where it would not depend
on the player exiting.