void SongSelect::initSongs(lua_State* L)
{
// code based off of code found on Google, with modifications to create the track objects
WIN32_FIND_DATA file_search;
HANDLE handle = FindFirstFile("Assets/Scripts/Songs/*.lua", &file_search);
do
{
Track track;
std::string song_file;
std::stringstream song_file_stream;
std::stringstream song_name;
song_file_stream << "Assets/Scripts/Songs/" << file_search.cFileName;
song_name << file_search.cFileName;
std::string name = song_name.str();
song_file = song_file_stream.str();
//song_files.push_back(song_file);
std::string sub_song = name.substr(0, name.size() - 4);
int error = luaL_loadfile(L, song_file.c_str());
if (error)
{
std::cout << lua_tostring(L, -1) << std::endl;
}
if (lua_pcall(L, 0 , 0, 0) != 0)
{
std::cout<<"Error (Song Init): "<<lua_tostring(L, -1)<<std::endl;
}
else
{
track = luabind::object_cast<Track>(luabind::globals(L)[sub_song.c_str()]);
Track* p_track = track.clone();
songs.push_back(p_track);
}
} while (FindNextFile(handle, &file_search));
FindClose(handle);
}
So I'm going to bump this thread. This is my new code, using Luabind instead of Luabridge. I still encounter the same issue, however I've found that it happens when I hit the lua_pcall() line for the third time. This corrupts the first two objects in the vector called songs.
Anyone have any tips on what I could do to fix the corruption issue?