Don't use invalid music indices. Fixes #1861

This commit is contained in:
Alexander van Gessel 2017-10-20 17:31:09 +02:00
parent dccd73d11f
commit d063aa077a
3 changed files with 9 additions and 4 deletions

View file

@ -96,8 +96,8 @@ static int impl_music_get(lua_State* L) {
}
if(strcmp(m, "current_i") == 0) {
size_t i = sound::get_current_track();
if(i == sound::get_num_tracks()) {
size_t i = sound::get_current_track_index();
if(i >= sound::get_num_tracks()) {
lua_pushnil(L);
} else {
lua_pushinteger(L, i + 1);

View file

@ -190,10 +190,14 @@ std::vector<std::shared_ptr<sound::music_track>>::const_iterator find_track(cons
namespace sound
{
unsigned int get_current_track()
unsigned int get_current_track_index()
{
return current_track_index;
}
std::shared_ptr<music_track> get_current_track()
{
return current_track;
}
std::shared_ptr<music_track> get_previous_music_track()
{
return previous_track;

View file

@ -104,7 +104,8 @@ void set_sound_volume(int vol);
void set_bell_volume(int vol);
void set_UI_volume(int vol);
unsigned int get_current_track();
unsigned int get_current_track_index(); // This function may return a value >= get_num_tracks(). Use with caution
std::shared_ptr<sound::music_track> get_current_track();
std::shared_ptr<sound::music_track> get_previous_music_track();
void set_previous_track(std::shared_ptr<music_track>);
unsigned int get_num_tracks();