Skip to content

Use consistent index cast type in onMixSamples - #314

Merged
daid merged 1 commit into
daid:masterfrom
GinjaNinja32:infinite-pitch
Oct 19, 2026
Merged

daid merged 1 commit into
daid:masterfrom
GinjaNinja32:infinite-pitch

Conversation

@GinjaNinja32

Copy link
Copy Markdown
Contributor

See discord conversation.

tl;dr size_t(infinity) == 0 but int(infinity) == -2^31, causing an out-of-bounds access. This PR results in an infinitely-playing sound, but that's better than a crash.

TODO: prevent infinite pitch somewhere earlier than this.

@GinjaNinja32

Copy link
Copy Markdown
Contributor Author

With master plus some debug prints, running
EmptyEpsilon server_scenario=scenario_27_liberation.lua scenario_settings='First=Seconds;Second=Seconds;Third=Seconds',
selecting main screen, then unpausing, I get:

INFO: onMixSamples(count=4096, sound->samples=438440, sound->samplerate=44100, sound->channels=2, index=115680.98, pitch=0.70, index_offset=0.70)
INFO: onMixSamples(count=4096, sound->samples=438440, sound->samplerate=44100, sound->channels=2, index=117120.98, pitch=0.70, index_offset=0.70)
INFO: onMixSamples(count=4096, sound->samples=438440, sound->samplerate=44100, sound->channels=2, index=118560.98, pitch=0.70, index_offset=0.70)
INFO: Loaded: sfx/laser_fire.wav of 0.90 seconds
INFO: onMixSamples(count=4096, sound->samples=39651, sound->samplerate=44100, sound->channels=1, index=0.00, pitch=inf, index_offset=inf)
INFO: idx=inf size_t(idx)=0 int(idx)=-2147483648 sss=39651
/usr/include/c++/16/bits/stl_vector.h:1272: std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = short int; _Alloc = std::allocator<short int>; const_reference = const short int&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.

@daid
daid merged commit bbe714a into daid:master Oct 19, 2026
6 checks passed
@daid

daid commented Oct 19, 2026

Copy link
Copy Markdown
Owner

preventing crashes is always good.

@GinjaNinja32
GinjaNinja32 deleted the infinite-pitch branch October 19, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants