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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - AnoHito

Pages: [1]
1
D / Bizzare issue playing audio files
« on: June 01, 2014, 07:37:49 am »
Hi, so just as a disclaimer, I am very new to both the D programming language and SFML, so there could easily be a facepalm worthy cause behind my current issue, but if there is I can't find it. I'm currently trying to get a simple test program that uses DSFML to work correctly. Here is my current code:

module winmain;

import core.runtime;
import core.sys.windows.windows;

import dsfml.system;
import dsfml.window;
import dsfml.graphics;
import dsfml.audio;

extern (Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    int result;

    try
    {
        Runtime.initialize();
        result = myWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
    }
    catch (Throwable error)             // catch any uncaught exceptions
    {
        MessageBoxA(null, cast(char *)error.toString(), "Error", MB_OK | MB_ICONEXCLAMATION);
        result = 0;             // failed
    }

    return result;
}

int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
        void errorMessage(Throwable error)
        {
        MessageBoxA(null, cast(char *)error.toString(), "Error", MB_OK | MB_ICONEXCLAMATION);
        }

    // Load a sprite to display
        Texture texture;
        Sprite sprite;

    try
    {
                texture = new Texture();
                if(!texture.loadFromFile("cute_image.png"))
                        return 0;
                sprite = new Sprite(texture);
    }
    catch (Throwable error)
    {
                errorMessage(error);
        }

    // Create the main window
        auto size = texture.getSize();
    auto window = new RenderWindow(VideoMode(size.x, size.y), "DSFML window");

    // Create a graphical text to display
    auto font = new Font();
    if(!font.loadFromFile("arial.ttf"))
        return 0;
    auto text = new Text("Hello DSFML", font, 50);
        text.setColor(Color.Black);

        // Load a music to play
    try
    {
                auto music = new Music();
                if(!music.openFromFile("nice_music.ogg"))
                        return 0;

                // Play the music
                music.play();
    }
    catch (Throwable error)
    {
                errorMessage(error);
        }

    // Start the game loop
    while(window.isOpen())
    {
        // Process events
        Event event;
        while(window.pollEvent(event))
        {
            // Close window
            if(event.type == Event.EventType.Closed)
                window.close();
        }

        // Clear screen
        window.clear();

        // Draw the sprite
        window.draw(sprite);

        // Draw the string
        window.draw(text);

        // Update the window
        window.display();
    }

    return 0;
}
 

The problem is that while the audio file will load correctly, the program will throw a "Bad file descriptor" error when I actually try to play it. And if that weren't bad enough, when I try to close the program I get the following runtime error:

Quote
Unhandled exception at 0x7736A4B9 (ole32.dll) in DSFML_Example.exe: 0xC0000005: Access violation reading location 0xFEEEFEEE.

I really have no idea what's going on here. Looking through my code and configuration, it's not clear at all that I did anything horribly wrong. Here is a link to my entire Visual Studio project in case anyone wants to look at it (it requires you to have Visual D installed).

Pages: [1]
anything