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

Recent Posts

Pages: [1] 2 3 ... 10
1
Audio / Re: Music not playing even though its loaded.
« Last post by Me-Myself-And-I on April 24, 2024, 06:08:16 pm »

Quote
Why this would have an impact on the music playing or not playing, I don't know, since those are separate modules without any overlaps.  ???
I too thought that was very strange.


Quote
You shouldn't use any SFML resources globally, in general avoid globals as much as possible.
Initialization and destruction order at a global scope aren't guaranteed, so you can run into issues where some expected internal SFML global isn't initialize or already destructed, leading to crashes. As for globals in general, they make it very hard to impossible to track the state and code flow at any given moment.

The solution is for me to make a better habit of not declaring SFML elements globally. Thankyou for your help.


Quote
I tried the same code (both global and local window) and music played fine in both cases. Although I'm using SFML 3 so maybe it doesn't have the issue.
I even tried playing the music without a window and it worked. (I replaced the while open loop with a Sleep(10000)).

But I see some bits of the audio system have changed since SFML 2.5 with how the global audio device is handled.

Yes, its likely that this problem was fixed in sfml 3. I use 2.4.0 so it might be more likely for this error to occur in this version when the window is declared globally.
2
Audio / Re: Music not playing even though its loaded.
« Last post by kojack on April 24, 2024, 08:56:45 am »
I tried the same code (both global and local window) and music played fine in both cases. Although I'm using SFML 3 so maybe it doesn't have the issue.
I even tried playing the music without a window and it worked. (I replaced the while open loop with a Sleep(10000)).

But I see some bits of the audio system have changed since SFML 2.5 with how the global audio device is handled.
3
Audio / Re: Music not playing even though its loaded.
« Last post by eXpl0it3r on April 24, 2024, 07:55:36 am »
You shouldn't use any SFML resources globally, in general avoid globals as much as possible.
Initialization and destruction order at a global scope aren't guaranteed, so you can run into issues where some expected internal SFML global isn't initialize or already destructed, leading to crashes. As for globals in general, they make it very hard to impossible to track the state and code flow at any given moment.

Why this would have an impact on the music playing or not playing, I don't know, since those are separate modules without any overlaps.  ???
4
Audio / Re: Music not playing even though its loaded.
« Last post by Me-Myself-And-I on April 24, 2024, 02:55:33 am »
So strange. I cut it down to a bare minimum and I located the problem at the window declaration.

In main.h
#include <SFML\Graphics.hpp>




extern sf::RenderWindow window;
 


In main.cpp
#include <SFML\Graphics.hpp>
#include <SFML\Audio.hpp>
#include "main.h"
#include <windows.h>




               
sf::RenderWindow window(sf::VideoMode(960,540),"Weather Dodger");



int main()
{
       
       
       






        sf::Music themusic;
        if(!themusic.openFromFile("ASSETS/snow.wav"))
        {
                MessageBox(NULL,"Not found","Error",MB_OK);

        }
        themusic.setVolume(100);
        themusic.play();


        while(window.isOpen())
        {

                sf::Event e;
                while(window.pollEvent(e))
                {
                        if(e.type==sf::Event::Closed)
                                window.close();
                }
               
       
               
               
               
               
               
               
               
               
                window.clear();

                window.display();
        }
}



 

With this code the music does not play.


But with window declared locally theres no problem.Any ideas why this problem occurs?

In main.cpp with window local.

#include <SFML\Graphics.hpp>
#include <SFML\Audio.hpp>
#include "main.h"
#include <windows.h>




               



int main()
{
       
       
       



        sf::RenderWindow window(sf::VideoMode(960,540),"Weather Dodger");



        sf::Music themusic;
        if(!themusic.openFromFile("ASSETS/snow.wav"))
        {
                MessageBox(NULL,"Not found","Error",MB_OK);

        }
        themusic.setVolume(100);
        themusic.play();


        while(window.isOpen())
        {

                sf::Event e;
                while(window.pollEvent(e))
                {
                        if(e.type==sf::Event::Closed)
                                window.close();
                }
               
       
               
               
               
               
               
               
               
               
                window.clear();

                window.display();
        }
}








 

Seems like a window error to me.But why? :P
5
Audio / Re: Music not playing even though its loaded.
« Last post by eXpl0it3r on April 23, 2024, 10:35:19 am »
Can you provide a compilable and minimal example that reproduces the problem?

On its own the code you showed should work.

Make sure you're using the OpenAL DLL that ships with SFML and not your own version or a version that's somewhere in PATH.
6
Audio / (SOLVED)Music not playing even though its loaded.
« Last post by Me-Myself-And-I on April 23, 2024, 12:43:38 am »
I have this strange problem where the music is loaded but nothing happens when the program is run.

This is put before my window.isOpen() loop.
        Music themusic;
        if(!themusic.openFromFile("ASSETS/snow.wav"))
        {
                MessageBox(NULL,"Not found","Error",MB_OK);

        }
        themusic.setVolume(100);
        themusic.play();


The game updates fine.Theres no freezing going on.And I'm sure the audio file works.I have been using audio files in music and suddenly it doesn't make a sound.I'm sure my computer audio works too because sf::sound works. Either i'm doing something wrong here or something in my other code is stopping themusic. I'm certain there is no themusic.stop() anywhere in my code so i'm wondering if its some sort of problem with sfml. I did use 500 sounds. Could this effect sf:Music? I know. Why use 500 sounds? Well its actually for a sound that is played very fast so I need it.
Any ideas where the problem is?
Thanks
7
General / Re: Raycast failed
« Last post by eXpl0it3r on April 22, 2024, 08:28:40 am »
You need to provide more information if you want help.

People won't go watch a full YouTube video, just to understand what's going.

Use a debugger to understand how values change and make sure you understand what should be happening, so you can check if the values are correct and wrong.
8
General / Re: How to realize a state machine based SFML?
« Last post by eXpl0it3r on April 22, 2024, 08:25:07 am »
In my SmallGameEngine state machine example, I can create a new state anywhere in the code, it will be stored as m_next and only applied in the next state machine loop iteration.

This guarantees that the state doesn't just suddenly change and leaves the freedom to create a new state anywhere within the current state.
9
General / Re: Pass int/char array to sf::Uint8 array?
« Last post by kojack on April 21, 2024, 11:30:33 pm »
If we're dealing with 32bit colour (usually are), a char is only a quarter of the colour. But an int can hold an entire colour at once. So right now you are working with quarter pixels instead of whole pixels.

Having
unsigned int* pixels = new unsigned int [1280 * 720];

for (int i = 0; i < 1280 * 720; i++)
    pixels[i] = 0xff0080ff;  // that should be orange on an RGBA 32 bit pixel, which is what SFML uses
Means you are working one pixel at a time, and the for loop code does a quarter of the work.
10
I just realized, this is in the description of the contains() function:
Check if a point is inside the rectangle&#39;s area This check is non-inclusive. If the point lies on the edge of the rectangle, this function will return false.

Could this be related to the problem, even though my collisions work in some cases perfectly?
Pages: [1] 2 3 ... 10