mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-08 21:31:46 +08:00
engine: client: sound: harden S_AdjustLoopedSamplePosition against invalid loopstart also
This commit is contained in:
@@ -68,13 +68,14 @@ static int S_AdjustLoopedSamplePosition( const wavdata_t *source, int current_sa
|
||||
// check if looping is enabled and we've exceeeded the sample boundary
|
||||
if( enable_looping && FBitSet( source->flags, SOUND_LOOPED ) && current_sample >= source->samples )
|
||||
{
|
||||
// adjust position relative to loop start
|
||||
current_sample -= source->loop_start;
|
||||
int loop_start = Q_min( source->loop_start, source->samples );
|
||||
int loop_range = source->samples - loop_start;
|
||||
|
||||
// apply modulo to wrap within loop bounds
|
||||
int loop_range = source->samples - source->loop_start;
|
||||
if( loop_range > 0 )
|
||||
current_sample = source->loop_start + ( current_sample % loop_range );
|
||||
current_sample = loop_start + (( current_sample - loop_start ) % loop_range );
|
||||
else
|
||||
current_sample = source->samples;
|
||||
}
|
||||
|
||||
return current_sample;
|
||||
|
||||
Reference in New Issue
Block a user