From 0566c16b69a0ab395aa342bae0b198af4502d258 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sun, 13 Dec 2015 12:51:13 +0000 Subject: [PATCH] sampler: add a few sanity checks to sampler. --- src/sampler.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/sampler.cpp b/src/sampler.cpp index d1efebc2..f3380d85 100644 --- a/src/sampler.cpp +++ b/src/sampler.cpp @@ -47,25 +47,35 @@ int Sampler::Register(char const *path) void Sampler::Deregister(int id) { - data->samples.RemoveSlot(id - 1); /* ID 0 is for the empty sample */ + if (id > 0) + data->samples.RemoveSlot(id - 1); /* ID 0 is for the empty sample */ } void Sampler::PlaySample(int id) { - Sample *sample = (Sample *)data->samples.GetEntity(id - 1); - sample->Play(); + if (id > 0) + { + Sample *sample = (Sample *)data->samples.GetEntity(id - 1); + sample->Play(); + } } void Sampler::LoopSample(int id) { - Sample *sample = (Sample *)data->samples.GetEntity(id - 1); - sample->Loop(); + if (id > 0) + { + Sample *sample = (Sample *)data->samples.GetEntity(id - 1); + sample->Loop(); + } } void Sampler::StopSample(int id) { - Sample *sample = (Sample *)data->samples.GetEntity(id - 1); - sample->Stop(); + if (id > 0) + { + Sample *sample = (Sample *)data->samples.GetEntity(id - 1); + sample->Stop(); + } } } /* namespace lol */