fix reference to resources directory on OS X

This commit is contained in:
Stephen Birarda 2013-04-17 11:56:32 -07:00
parent 0768785cfd
commit e9592c45c7
4 changed files with 6 additions and 5 deletions

View file

@ -444,8 +444,8 @@ Audio::Audio(Oscilloscope *s, Head *linkedHead)
// read the walking sound from the raw file and store it // read the walking sound from the raw file and store it
// in the in memory array // in the in memory array
switchToResourcesIfRequired(); switchToResourcesParentIfRequired();
FILE *soundFile = fopen("audio/walking.raw", "r"); FILE *soundFile = fopen("resources/audio/walking.raw", "r");
// get length of file: // get length of file:
std::fseek(soundFile, 0, SEEK_END); std::fseek(soundFile, 0, SEEK_END);

View file

@ -114,7 +114,7 @@ Head::Head() {
springVelocityDecay = 16.0f; springVelocityDecay = 16.0f;
if (iris_texture.size() == 0) { if (iris_texture.size() == 0) {
switchToResourcesIfRequired(); switchToResourcesParentIfRequired();
unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file);
if (error != 0) { if (error != 0) {
std::cout << "error " << error << ": " << lodepng_error_text(error) << std::endl; std::cout << "error " << error << ": " << lodepng_error_text(error) << std::endl;

View file

@ -74,7 +74,7 @@ bool oneAtBit(unsigned char byte, int bitIndex) {
return (byte >> (7 - bitIndex) & 1); return (byte >> (7 - bitIndex) & 1);
} }
void switchToResourcesIfRequired() { void switchToResourcesParentIfRequired() {
#ifdef __APPLE__ #ifdef __APPLE__
CFBundleRef mainBundle = CFBundleGetMainBundle(); CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
@ -85,6 +85,7 @@ void switchToResourcesIfRequired() {
CFRelease(resourcesURL); CFRelease(resourcesURL);
chdir(path); chdir(path);
chdir("..");
#endif #endif
} }

View file

@ -47,7 +47,7 @@ void printVoxelCode(unsigned char* voxelCode);
int numberOfOnes(unsigned char byte); int numberOfOnes(unsigned char byte);
bool oneAtBit(unsigned char byte, int bitIndex); bool oneAtBit(unsigned char byte, int bitIndex);
void switchToResourcesIfRequired(); void switchToResourcesParentIfRequired();
const char* getCmdOption(int argc, const char * argv[],const char* option); const char* getCmdOption(int argc, const char * argv[],const char* option);
bool cmdOptionExists(int argc, const char * argv[],const char* option); bool cmdOptionExists(int argc, const char * argv[],const char* option);