Finding Files in a Directory on Windows, with Lua Scripts : Issue I Can't Figure Out

Started by
10 comments, last by c_fried_rice 10 years, 2 months ago

Hey guys, I have a pretty MAJOR issue with some of my code for a game I'm working on.

Basically, I have the following code to find all the lua scripts and then grab some information from them on a selection screen. It works fine when I run it from Visual Studio 2012 (as both release and debug) but doesn't appear to function properly. Some pictures don't appear, and some random text characters appear instead of the actual text, and in some place there's on text whatsoever. I don't have any include how to debug this to be honest.

Here's the code that initializes all the stuff.


void SongSelect::init(GamestateManager* gameStateManager, lua_State* L)
{
	m_pInputManager = InputManager::Instance();
	ImageManager* m_pImageManager = ImageManager::Instance();
	Game* m_pGame = Game::Instance();
	AudioManager* m_pAudioManager = AudioManager::Instance();

	songs = initSongs(L);
	std::cout << "Attemping to read songselect.lua\n";
	luaL_dofile(L, "Assets/Scripts/States/SongSelect.lua");
	std::cout << "Read songselect.lua\n";

	m_pImageManager->load(bg, "bg", m_pGame->getRenderer());

	current_pad = old_pad = NULL;


	initAlbumArt(songs);

	info_col.a = 200;
	info_col.r = 255;
	info_col.g = 255;
	info_col.b = 255;

	TextManager::Instance()->loadText(font, label, 36);

	selected = 0;
}

std::vector<Track*> SongSelect::initSongs(lua_State* L)
{
	std::vector<Track*> tracks;

	// 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);

	while (handle != INVALID_HANDLE_VALUE)
	{
		std::string song_file;
		std::stringstream song_file_stream;
		song_file_stream << "Assets\\Scripts/Songs\\" << file_search.cFileName;
		song_file = song_file_stream.str();

		song_files.push_back(song_file);

		luaL_dofile(L, song_file.c_str());
		Track* track = luabridge::getGlobal(L, "music_track");
		tracks.push_back(track);

		if (!FindNextFile(handle, &file_search))
		{
			break;
		}
	}

	FindClose(handle);

	return tracks;
}

Any ideas why this may work when run from Visual Studio 2012 but not when launched directly from Windows Explorer in a different location? It makes it kind of hard to playtest/ release the game if I can't even get it to run properly on other computers!

Thanks a ton!

Advertisement

The working directory when running the executable in Visual Studio is usually your project directory instead of the location where the executable file is, so all of your relative paths might be working off of your project directory but not the /Relase and /Debug directories. You can make sure the folder with your executable also contains your Assets folder. You could also change your path variable or set a working directory.

Unfortunately, I don't think that's it because I've made sure that the Assets directory is copied into the /Release and /Debug directories when I try to run it outside of Visual Studio. It's also important to note, that this problem only has appeared since adding in the code for the select screen. =S

Is music_track overwritten/defined anew in every .lua file?

Does your luabridge handle that gracefully? Because it looks like you store a Track* to a lua object that's being deleted.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Is music_track overwritten/defined anew in every .lua file?

Does your luabridge handle that gracefully? Because it looks like you store a Track* to a lua object that's being deleted.

So this is what a .lua file in Song Select looks like:


-- Lua Constructor
music_track = Track();

-- Audio
music_track.music = "Assets/Audio/Songs/Playable/kevin_macleod_blown_away/kevin_macleod_blown_away.ogg";

-- Midi Note Charts
music_track.midi = "Assets/Audio/Songs/Playable/kevin_macleod_blown_away/kevin_macleod_blown_away.mid";
-- Song Info
music_track.title = "Blown Away";
music_track.artist = "Kevin Macleod";
music_track.genre = "Electro Rock";
music_track.album = "N/A";

music_track.album_art = StaticUI();
music_track.album_art.filename = "Assets/Audio/Songs/Playable/kevin_macleod_blown_away/aa_1.png";
music_track.album_art.texture = music_track.album;
music_track.album_art.frames = 1;
music_track.album_art.rows = 1;
music_track.album_art.frame = 0;
music_track.album_art.row = 0;
music_track.album_art.x = 5;
music_track.album_art.y = 100;
music_track.album_art.width = 256;
music_track.album_art.height = 256;
music_track.album_art.speed = 1;
music_track.album_art.flip = false;
music_track.album_art.alpha = 255;

music_track.album_art:init(music_track.album_art.x, music_track.album_art.y,
  music_track.album_art.width, music_track.album_art.height,
  music_track.album_art.filename, music_track.album_art.texture, music_track.album_art.flip);

music_track.l_track = "Synth";
music_track.r_track = "Drums";
music_track.year = "2012";
music_track.bpm = 135;

So yes, I would say it's defined anew in every Lua file. I guess my question then is, why would this work fine when launched from VS2012 but not fine when launched directly from an .exe in a folder WITH the assets folder and all necessary libraries included?

And should it be an issue with redefinition, how would I fix that?

Thanks!

It's hard to say with knowing how luabridge handles your Track objects. It does look like a solid wrapper so I guess it does it right.

If it keeps the encapsulated lua object alive the issue is not your script handling.

You might rule out path related problems by printing the found paths somewhere. Actually also write a hex dump of the strings you find. The weird values you found might be a give away.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

So I printed out some of the values and have copied them below. The first batch is when the songs are being gathered in the initSongs() function. The second batch is after it's called in init().



N/A
Kevin Macleod
Blown Away
Electro Rock
2012
Assets/Audio/Songs/Playable/kevin_macleod_blown_away/kevin_macleod_blown_away.mid
Assets/Audio/Songs/Playable/kevin_macleod_blown_away/kevin_macleod_blown_away.ogg
00AEAC14
00AEAC0C
00AEAC08
00AEAC10
00AEAC1C
00AEAC04
00AEAC00

The Hunter
Mastodon
Dry Bone Valley
Metal
2011
Assets/Audio/Songs/Playable/mastodon_dry_bone_valley/mastodon_dry_bone_valley.mid
Assets/Audio/Songs/Playable/mastodon_dry_bone_valley/mastodon_dry_bone_valley.ogg
00AE8624
00AE861C
00AE8618
00AE8620
00AE862C
00AE8614
00AE8610

Origin of Symmetry
Muse
Plug In Baby
Alternative
2001
Assets/Audio/Songs/Playable/muse_plug_in_baby/muse_plug_in_baby.mid
Assets/Audio/Songs/Playable/muse_plug_in_baby/muse_plug_in_baby.ogg
00AE881C
00AE8814
00AE8810
00AE8818
00AE8824
00AE880C
00AE8808

The Slip
Nine Inch Nails
1,000,000
Industrial
2008
Assets/Audio/Songs/Playable/nin_1000000/nin_1000000.mid
Assets/Audio/Songs/Playable/nin_1000000/nin_1000000.ogg
00AD6CB4
00AD6CAC
00AD6CA8
00AD6CB0
00AD6CBC
00AD6CA4
00AD6CA0

Hesitation Marks
Nine Inch Nails
Came Back Haunted
Industrial
2013
Assets/Audio/Songs/Playable/nin_came_back_haunted/came_back_haunted_nin.mid
Assets/Audio/Songs/Playable/nin_came_back_haunted/Came Back Haunted.ogg
00AE58D4
00AE58CC
00AE58C8
00AE58D0
00AE58DC
00AE58C4
00AE58C0

Psybrid Theory
Rosalina Sama & Triple Q
One Style Closer
Mash Up
2013
Assets/Audio/Songs/Playable/rosalinasama_one_style_closer/rosalinasama_one_style_closer.mid
Assets/Audio/Songs/Playable/rosalinasama_one_style_closer/rosalinasama_one_style_closer.ogg
00AEB614
00AEB60C
00AEB608
00AEB610
00AEB61C
00AEB604
00AEB600



xQ±



2012
<
Assets/Audio/Songs/Playable/kevin_macleod_blown_away/kevin_macleod_blown_away.ogg
00AEAC14
00AEAC0C
00AEAC08
00AEAC10
00AEAC1C
00AEAC04
00AEAC00


Mastodon
Dry Bone Valley
Metal
2011
Assets/Audio/Songs/Playable/mastodon_dry_bone_valley/mastodon_dry_bone_valley.mid
Assets/Audio/Songs/Playable/mastodon_dry_bone_valley/mastodon_dry_bone_valley.ogg
00AE8624
00AE861C
00AE8618
00AE8620
00AE862C
00AE8614
00AE8610

Origin of Symmetry
Muse
Plug In Baby

2001
Assets/Audio/Songs/Playable/muse_plug_in_baby/muse_plug_in_baby.mid
Assets/Audio/Songs/Playable/muse_plug_in_baby/muse_plug_in_baby.ogg
00AE881C
00AE8814
00AE8810
00AE8818
00AE8824
00AE880C
00AE8808


Nine Inch Nails

Industrial
2008
Assets/Audio/Songs/Playable/nin_1000000/nin_1000000.mid
Assets/Audio/Songs/Playable/nin_1000000/nin_1000000.ogg
00AD6CB4
00AD6CAC
00AD6CA8
00AD6CB0
00AD6CBC
00AD6CA4
00AD6CA0

Hesitation Marks
Nine Inch Nails
Came Back Haunted
Industrial
2013
Assets/Audio/Songs/Playable/nin_came_back_haunted/came_back_haunted_nin.mid
Assets/Audio/Songs/Playable/nin_came_back_haunted/Came Back Haunted.ogg
00AE58D4
00AE58CC
00AE58C8
00AE58D0
00AE58DC
00AE58C4
00AE58C0

Psybrid Theory
Rosalina Sama & Triple Q
One Style Closer
Mash Up
2013
Assets/Audio/Songs/Playable/rosalinasama_one_style_closer/rosalinasama_one_style_closer.mid
Assets/Audio/Songs/Playable/rosalinasama_one_style_closer/rosalinasama_one_style_closer.ogg
00AEB614
00AEB60C
00AEB608
00AEB610
00AEB61C
00AEB604
00AEB600

The hex values look like pointers (I actually meant the content of the string as hex dump), what kind of type are the strings you use? std::string or char* ?

Can you show the definition of your Track class?

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

The hex values look like pointers (I actually meant the content of the string as hex dump), what kind of type are the strings you use? std::string or char* ?

Can you show the definition of your Track class?


class Track
{
public:

	Track();

	void init();

	~Track();

	std::string music;
	std::string midi;
	std::string title;
	std::string artist;
	std::string genre;
	std::string album;
	int starting_track;
	std::string year;
	int bpm;
	std::string left_track;
	std::string right_track;
	StaticUI* album_art;

	unsigned int elapsedTimeMS;
};

That's the Track class, it's basically just a container for the necessary variables. Now for a stupid question, how can I easily get a Hex Dump of my output? >.>

With std::out like this:

std::cout << std::hex << n << '\n';

However it only works on primitive types, so you need to output strings char by char.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

This topic is closed to new replies.

Advertisement