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

Author Topic: Program crash when opening music  (Read 2903 times)

0 Members and 1 Guest are viewing this topic.

johnscape

  • Newbie
  • *
  • Posts: 2
    • View Profile
Program crash when opening music
« on: December 11, 2017, 02:24:05 pm »
So, I have been working on a little project of mine, and I have encountered a bug.
I have a special class for cinematics, where I use two music: a base and a special. I declare them in the header:
#ifndef INTROSCENE_H
#define INTROSCENE_H

#include "Screens/CinematicScreen.h"
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

class CharaIntroScene : public CinematicScreen
{
public:
        IntroScene(GameManager* gameManager);
        virtual ~IntroScene();
private:
       sf::Music Base;
       sf::Music Special;
};

#endif
 

And my source file:
#include "Screens/Cinematics/IntroScene.h"

IntroScene::IntroScene(GameManager* gameManager) : CinematicScreen(gameManager)
{
    Base.openFromFile("Assets/Music/Base.ogg");
    Special.openFromFile("Assets/Music/Special.ogg");

    Base.setLoop(true);
    Special.setLoop(true);
}
 

and I have a void where I start the music.
This way the game freeze and crash on load.
If I comment out the openFromFile part it loads.

I'm using windows 10 with codeblocks, and the corresponding SFML version.
Everything else is included, the dll files are in place.
And if I use the debugger, everything works, even the music plays. But it only works with the debugger.

So, what can be the problem?

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: Program crash when opening music
« Reply #1 on: December 11, 2017, 03:47:08 pm »
Quote
I have a void where I start the music.

what do you mean? show the code

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Program crash when opening music
« Reply #2 on: December 11, 2017, 03:49:43 pm »
If there's different behavior between debug and release, it usually is a memory problem (e.g. uninitialized memory, etc).

Try to create a minimal example, e.g. take your class, remove the base class and create an instance in main() and see if it's still an issue.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

johnscape

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Program crash when opening music
« Reply #3 on: December 11, 2017, 07:07:44 pm »
Okay, I put the music out to the main cpp, now it works. It means, that I should use the release files, not the debug ones?

Edit: So, I tried to use the release files. Now, it won't crash, but from loading the music to playing the music, it's lagging.

Edit: I'm confused. It started working with the debug files. I don't know why, maybe I just had to rebuild it. Still, it's lagging a bit until I start playing the music.

Edit: The lagg was my fault. So, the music started playing after I rebuild once with the release files, then againg with the debug files. Thank you for the answers!
« Last Edit: December 11, 2017, 07:45:05 pm by johnscape »