diff --git a/src/layout/layered.c b/src/layout/layered.c index 85f24344..de392ef8 100644 --- a/src/layout/layered.c +++ b/src/layout/layered.c @@ -95,6 +95,10 @@ void loop_layout_layered(VGMSTREAM* vgmstream, int32_t loop_sample) { data->layers[layer]->current_sample = data->layers[layer]->loop_end_sample; /* forces do loop */ vgmstream_do_loop(data->layers[layer]); /* guaranteed to work should loop_layout be called */ } + else { + /* needed when mixing non-looping layers and installing loop externally */ + seek_vgmstream(data->layers[layer], loop_sample); + } } } diff --git a/src/vgmstream.c b/src/vgmstream.c index f3697f4a..fb46a868 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -796,6 +796,12 @@ void close_vgmstream(VGMSTREAM* vgmstream) { void vgmstream_force_loop(VGMSTREAM* vgmstream, int loop_flag, int loop_start_sample, int loop_end_sample) { if (!vgmstream) return; + /* ignore bad values (may happen with layers + TXTP loop install) */ + if (loop_flag && (loop_start_sample < 0 || + loop_start_sample > loop_end_sample || + loop_end_sample > vgmstream->num_samples)) + return; + /* this requires a bit more messing with the VGMSTREAM than I'm comfortable with... */ if (loop_flag && !vgmstream->loop_flag && !vgmstream->loop_ch) { vgmstream->loop_ch = calloc(vgmstream->channels, sizeof(VGMSTREAMCHANNEL));