Skip to content

Commit

Permalink
Don't use invalid music indices. Fixes #1861
Browse files Browse the repository at this point in the history
  • Loading branch information
AI0867 committed Oct 20, 2017
1 parent dccd73d commit d063aa0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/scripting/lua_audio.cpp
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/sound.cpp
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/sound.hpp
Expand Up @@ -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();
Expand Down

0 comments on commit d063aa0

Please sign in to comment.