SFML community forums

Help => Audio => Topic started by: virus on September 11, 2010, 12:27:03 am

Title: struct + sf::Music + malloc = error (?)
Post by: virus on September 11, 2010, 12:27:03 am
Hello!

I am trying to have sf::Music into a dynamic list (struct below):

typedef struct sound{
    sf::Music audio;
    char *name;
    struct sound *next;
}sound;

When I declare:

sound test;
test.audio.OpenFromFile("music.ogg");
test.audio.Play();

it works.

But when I do:

sound *test;
test = (sound*)malloc(sizeof(sound));
test->audio.OpenFromFile("music.ogg");
test->audio.Play();

It doesn't work.

(I know, I am no treating the char stuff, but i just didn't post it here...)

Why doesn't it work?
Title: struct + sf::Music + malloc = error (?)
Post by: Lupinius on September 11, 2010, 12:57:35 am
When using C++ you shouldn't use malloc, use new instead.
Code: [Select]
sound *test;
test = new sound;
Title: struct + sf::Music + malloc = error (?)
Post by: virus on September 11, 2010, 01:02:31 am
It worked o.o"

Such an easy solution!

Thanks a LOT! :P
Title: struct + sf::Music + malloc = error (?)
Post by: virus on September 11, 2010, 01:17:30 am
What about playing the same music 2 times at almost the same time without stopping the first?

I mean, i am playing a music, and then I want it to start again, without stopping the first music to play, so it starts again and the same music is playing in 2 different positions.

How can I do that?
Title: struct + sf::Music + malloc = error (?)
Post by: Lupinius on September 11, 2010, 01:30:29 am
Have two music objects.
Title: struct + sf::Music + malloc = error (?)
Post by: virus on September 11, 2010, 01:39:44 am
There is no other way? It is too slow and heavy.

Afterall, i cannot know how many times will i have to play the same song simultaneously :/
Title: struct + sf::Music + malloc = error (?)
Post by: virus on September 11, 2010, 04:26:01 am
I did it!

SoundBuffer + Sound

Thanks for helping :)
Title: struct + sf::Music + malloc = error (?)
Post by: panithadrum on September 11, 2010, 12:05:55 pm
I think that sf::Music is one of the most light-weight class in the SFML library