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 - oddikaro

Pages: [1]
1
DotNet / AL lib: (EE) alc_cleanup: 1 device not closed
« on: July 09, 2021, 10:35:57 pm »
Hi all,

working with SMFL nuget package in .NET 5. I am experiencing 3 issues related with Sound:

1. When I close the window, the console shows this message:
AL lib: (EE) alc_cleanup: 1 device not closed

This is "not an issue" but would like to make it dissappear. I have tried using Sound.SoundBuffer.Dispose() and Sound.Dispose() when the window is closing. However, that does not seem to work in all situations. I think it mainly depends if the Sound instance belongs to the Game class (the one that has the event handler function when window is closing) or to another class (e.g., Player).

For instance, if I want to dispose Player's Sound's instance from Game's close window event handler function, it does not work (the message appears):


class Game{

...
public Player Player { get; set; }
...

        private void Window_Closed(object sender, EventArgs e)
        {
            Player.SoundBuffer.Dispose();
            Player.Sound.Dispose();
            (sender as RenderWindow).Close();


        }
 

In this same project, I have detected one exception

2. When I close the window "at the same time" the sound is going to play, an exception occurs in:

Sound.Play(); // System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'

It is not easy to reproduce this exception since I need to just close the window in a very specific time (seems so).

Maybe it is trying to run Play() when the Dispose() has already been executed (becasue the window has been closed from another class)¿? API comments state that Play uses another thread so maybe it is trying to access some data already deleted.

If you have any ideas, they are welcome!


2
DotNet / Dealing with events
« on: July 08, 2021, 07:20:30 pm »
Hi all,

I would like to move shape objects within the window. Events in SFML .NET are substantially different than using C++, e.g.:


...
        window.Closed += OnWindowClosed;
...

        private static void OnWindowClosed(object sender, EventArgs e)
        {
            (sender as RenderWindow).Close();
        }
 

That is possible since the sender object is the window itself, so you can do something with the window if you want. However, if you create a shape and you want to modify some properties when the keyboard is pressed, I don't see a clear way of doing it.

Of course, if the shape is accessible (e.g., "MyShape" as a property in the class), you can make changes in any arbitrary function:
        private static void OnKeyPressed(object sender, KeyEventArgs e)
        {
            if (e.Code == Keyboard.Key.Escape)
            {
                (sender as RenderWindow).Close();
            }
            if (e.Code == Keyboard.Key.Left)
            {
                MyShape.Position = new Vector2f(MyShape.Position.X - 10, MyShape.Position.Y);
            }
        }
 

However, I don't like to access external variables from an event function, I would prefer to pass them as a parameter. Or you may have another suggestion.

Pages: [1]