0
0

Hi,
I’ve got problems with opening an file. I have a function with returns the filename, and this filename should be played.
[code:2n9ib21h]
char* filename;

getMusic(step, type, filename);
//filename = "test1.mp3";
result = system->createSound(filename, FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &sound);
ERRCHECK(result);
[/code:2n9ib21h]
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

  • You must to post comments
0
0

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?

  • You must to post comments
0
0

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.

MYSQL_ROW row;

filename = row[2];

  • You must to post comments
0
0

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.

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.