music = Mix_LoadMUS(Current.music);
Mix_PlayMusic( music, -1 );
– Strong shortened, level is a opened text file, “Current” is a levelobject. The name of the path is loaded correctly and the very same works for my imagepaths-
any idea why the music doesn’t play?
if the the string zeile is modified between when you set Current.music and when Mix_LoadMUS is called (which it looks like it would be, based on the fact that you’re loading it with getline in a loop), its quite possible that the memory used to hold its C string has either been modified or been freed, which would make Current.music point either to invalid memory (your program should crash) or to the wrong memory contents (loading the file would fail).
Pro-tip: If you’re using C++, just use std::string and std::stringstream for all string manipulation. What you’re doing can be done quite easily with std::string::find and std::string::substr. Dealing with strings with the C functions is tedious, and if you’re not familiar with low-level memory operations, often results in unexpected behavior. Retaining a pointer or reference to anything on allocated on the stack is also a bad idea.------------------------
Nate Fries
There’s a lot of code missing that would be helpful. What jumps out to me
is the comparison “==” with a string literal. In C, use (strcmp(str1,
str2) == 0). If you are using C++, then definitely use C++.
Jonny DOn Sat, Mar 30, 2013 at 3:07 PM, Nathaniel J Fries wrote:
**
if the the string zeile is modified between when you set Current.music and
when Mix_LoadMUS is called (which it looks like it would be, based on the
fact that you’re loading it with getline in a loop), its quite possible
that the memory used to hold its C string has either been modified or been
freed, which would make Current.music point either to invalid memory (your
program should crash) or to the wrong memory contents (loading the file
would fail).
Pro-tip: If you’re using C++, just use std::string and std::stringstream
for all string manipulation. What you’re doing can be done quite easily
with std::string::find and std::string::substr. Dealing with strings with
the C functions is tedious, and if you’re not familiar with low-level
memory operations, often results in unexpected behavior. Retaining a
pointer or reference to anything on allocated on the stack is also a bad
idea.