I’ve got problems with opening an file. I have a function with returns the filename, and this filename should be played.
getMusic(step, type, filename);
//filename = "test1.mp3";
result = system->createSound(filename, FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &sound);
The prototype of the used function is:
void getMusic(int step, int &type, char* &filename)
When I try to get the filename out of the function, I always become an error, file not found. The returned filename looks like the filename I manually set an have the same length.
But when I set the filename directly, commented version, Fmod plays the file.
I have no idea wahts wrong, please help me!
- JoeSt asked 10 years ago
Well if it works when you uncomment that line then what’s different when you use the getMusic function? Is the returned filename identical? Does the string that "filename" points to go out of scope when getMusic returns? i.e. was it declared statically inside getMusic instead of dynamically?
The returned filename is identically, because, when I print out the filename via cout they are the same, even strcmp says that the filename is the same as the commented line.
in side the getMusic function, the path tp the music is read out from an MySQL-database.
filename = row;
- JoeSt answered 10 years ago
you should read more about the stack and C, you can’t just return a pointer to a stack object inside a function, it goes out of scope.
Make it static, or instead of returning a pointer, pass in some memory and copy the name to that.
Please login first to submit.