Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Error when tring to delete music file.  (Read 3063 times)

0 Members and 1 Guest are viewing this topic.

darekg11

  • Full Member
  • ***
  • Posts: 127
    • View Profile
Error when tring to delete music file.
« on: December 09, 2010, 03:28:55 pm »
Okay, so bassicly I used unRAR library to unrar my archieve which constainst graphics and also sounds for my game, everything works fine till deleting.

I can easlie delete all graphic files but can't delete sounds file.

Here's problem:
I use one sfMusic* Pointer to all types of clicking so bassicly when You click in that area You get another sound and when You click in another area You get another sound.

I also got one background music, which deletes without any problems, I think it's because I use it only for one purpose.(background music ofcourse)

When i want to switch music in that one pointer I do something like:
Pointer = sfMusic_CreateFromFile(blabla);
And when I closing my game I do something like:
Code: [Select]

sfMusic_Destroy(Pointer);
system("RD /S /Q Dzwieki"); <- directory with sounds

And I get permission error saying that I am tring to delete something that is already in use.
But if I don't click anywhere and just close the game it deletes without problem.

So how should I prevent this?
It's not working because of adressing different types of files to that same pointer, I tried nulling this pointer everyime I change it's file but it's not helping. I am sure about that because just now I ran some test, do I have to use different sfMusic for every music file that I want? Come one there's got to be some kind of solution.

Minimal code of problem:
Code: [Select]

extern "C"
{
#include <SFML/System.h>
#include <SFML/Audio.h>
#include <SFML/Window.h>
}
int main() //Name of files are "aaa.ogg" and "aaa1.ogg"
{
sfMusic* Tescior = NULL; <--- used for test
sfWindowSettings Ustawienia = {24, 8, 0};
sfVideoMode Tryb = {800, 600, 32};
sfRenderWindow* Glowne;
sfEvent Wydarzenie;
Glowne = sfRenderWindow_Create(Tryb, "Gra v0.1 Alpha", sfClose, Ustawienia);
while (sfRenderWindow_IsOpened(Glowne))
{
while (sfRenderWindow_GetEvent(Glowne, &Wydarzenie)) //Pobiera Wydarzenia
{
if (Wydarzenie.Type == sfEvtClosed) //Jesli wydarzenie to X
{
sfRenderWindow_Close(Glowne);
}
if (Wydarzenie.Type == sfEvtKeyPressed && Wydarzenie.Key.Code == sfKeyQ)
{
Tescior = sfMusic_CreateFromFile("aaa.ogg");
sfMusic_Play(Tescior);
}
if (Wydarzenie.Type == sfEvtKeyPressed && Wydarzenie.Key.Code == sfKeyE)
{
Tescior = sfMusic_CreateFromFile("aaa1.ogg");
sfMusic_Play(Tescior);
}


}
}
sfRenderWindow_Clear(Glowne, sfBlack);
sfRenderWindow_Display(Glowne);
}
     sfRenderWindow_Destroy(Glowne);
sfMusic_Destroy(Tescior);
remove("aaa.ogg");
remove("aaa1.ogg");
getch();
     return EXIT_SUCCESS;
 }

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Error when tring to delete music file.
« Reply #1 on: December 09, 2010, 06:17:07 pm »
You must destroy the previous music (sfRenderWindow_Destroy) before loading the new one. Otherwise it's a memory leak and your musics are never destroyed (except the very last one).
Laurent Gomila - SFML developer

darekg11

  • Full Member
  • ***
  • Posts: 127
    • View Profile
Error when tring to delete music file.
« Reply #2 on: December 09, 2010, 08:07:57 pm »
Worked, thanks I tried it later but forgot to set defauly value at the beggining.

Should i do the same with other objects like Images, Strings, Fonts, Sprites? Because I probably have big memory leak...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Error when tring to delete music file.
« Reply #3 on: December 09, 2010, 10:30:58 pm »
Absolutely, everything that is created must be destroyed.
Laurent Gomila - SFML developer