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

Author Topic: SFML stack overflow exception  (Read 3299 times)

0 Members and 1 Guest are viewing this topic.

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
SFML stack overflow exception
« on: September 22, 2015, 01:39:45 am »
I'm using SFML.Net 2.2, x64 build under Windows 7 x64.
And I caught a strange bug which sometimes unexpectedly terminates process.

Visual Studio 2012 didn't break execution, it just shows that process has exited with code 0x80000003...
I got the following error details from WinDbg64:

Critical error detected c0000374
(f8c.d94): Break instruction exception - code 80000003 (first chance)
ntdll!RtlUnhandledExceptionFilter+0x29f:
00000000`7718ff8f cc              int     3
0:019> ~* k

[...skipped...]

# 19  Id: f8c.d94 Suspend: 1 Teb: 000007ff`ffefe000 Unfrozen
Child-SP          RetAddr           Call Site
00000000`26b8ea00 00000000`77190606 ntdll!RtlUnhandledExceptionFilter+0x29f
00000000`26b8ead0 00000000`77191812 ntdll!EtwEnumerateProcessRegGuids+0x216
00000000`26b8eb00 00000000`771934f4 ntdll!RtlQueryProcessLockInformation+0x972
00000000`26b8eb30 00000000`7712b015 ntdll!RtlLogStackBackTrace+0x444
00000000`26b8eb60 00000000`76fd1a7a ntdll!RtlIsDosDeviceName_U+0x5555
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for G:\****\bin\Debug\x64\csfml-audio-2.DLL -
00000000`26b8ebe0 000007fe`ea27ef64 KERNEL32!HeapFree+0xa
00000000`26b8ec10 000007fe`ea278b7a csfml_audio_2!sfSoundStream_destroy+0xc0e4
00000000`26b8ec40 000007fe`ea279419 csfml_audio_2!sfSoundStream_destroy+0x5cfa
00000000`26b8ec70 000007fe`ea279807 csfml_audio_2!sfSoundStream_destroy+0x6599
00000000`26b8eca0 000007fe`ea277cdc csfml_audio_2!sfSoundStream_destroy+0x6987
00000000`26b8ecd0 000007fe`ea271b1a csfml_audio_2!sfSoundStream_destroy+0x4e5c
00000000`26b8ed00 000007fe`90c3f0e3 csfml_audio_2!sfSound_setBuffer+0x1a
00000000`26b8ed30 000007fe`90c3eab1 0x000007fe`90c3f0e3
00000000`26b8ee00 000007fe`ef0739a5 0x000007fe`90c3eab1
00000000`26b8eeb0 000007fe`ef073719 mscorlib_ni+0x4a39a5
00000000`26b8f010 000007fe`ef0a216f mscorlib_ni+0x4a3719
00000000`26b8f040 000007fe`ef0a136a mscorlib_ni+0x4d216f
00000000`26b8f090 000007fe`f026a7f3 mscorlib_ni+0x4d136a
00000000`26b8f150 000007fe`f026a6de clr+0xa7f3
00000000`26b8f190 000007fe`f026ae76 clr+0xa6de
00000000`26b8f1d0 000007fe`f02f0221 clr+0xae76
00000000`26b8f380 000007fe`f026c121 clr!GetMetaDataInternalInterface+0x31d01
00000000`26b8f470 000007fe`f026c0a8 clr+0xc121
00000000`26b8f4b0 000007fe`f026c019 clr+0xc0a8
00000000`26b8f5b0 000007fe`f026c15f clr+0xc019
00000000`26b8f640 000007fe`f02f01ae clr+0xc15f
00000000`26b8f6a0 000007fe`f02ef046 clr!GetMetaDataInternalInterface+0x31c8e
00000000`26b8f830 000007fe`f02eef3a clr!GetMetaDataInternalInterface+0x30b26
00000000`26b8f860 000007fe`f03afcb6 clr!GetMetaDataInternalInterface+0x30a1a
00000000`26b8f8f0 00000000`76fc5a4d clr!CopyPDBs+0x44a2
00000000`26b8f930 00000000`770fb831 KERNEL32!BaseThreadInitThunk+0xd
00000000`26b8f960 00000000`00000000 ntdll!RtlUserThreadStart+0x21

I'm using two instances of Sound to play the game sound effects.
I'm need two instances, because sound events may be raised quickly, but the class Sound is able to play a single SoundBuffer simultaneously.

The code is here:
        private void PlaySound(SoundEffect sfx)
        {
            if (_sound.Count == 0 || !_sndMap.ContainsKey(sfx))
            {
                return;
            }
            ThreadPool.QueueUserWorkItem(state =>
            {
                var sound = _sound
                    .FirstOrDefault(arg => arg.Status != SoundStatus.Playing);
                sound = sound ?? _sound.FirstOrDefault();
                if (sound != null && _sndMap.ContainsKey(sfx))
                {
                    sound.SoundBuffer = _sndMap[sfx];
                    sound.Play();
                }
            });
        }

The dictionary _sndMap contains instances of SoundBuffer with pre-loaded OGG file (with duration 1-2 seconds).

Could you please help me to fix that issue?
I'm using .net framework 4.5.2 if it helps.
Thanks


zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: SFML stack overflow exception
« Reply #1 on: September 22, 2015, 07:13:14 pm »
Can you post a complete and minimal code example that shows the problem?
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: SFML stack overflow exception
« Reply #2 on: September 23, 2015, 01:25:52 am »
I posted minimal code. Initialization is the following:

        private readonly List<Sound> _sound = new List<Sound>();
        private readonly Dictionary<SoundEffect, SoundBuffer> _sndMap = new Dictionary<SoundEffect, SoundBuffer>();

        private void LoadResources()
        {
            _sound.Add(new Sound());
            _sound.Add(new Sound());
            _sndMap[SoundEffect.GameStart] = new SoundBuffer(getPath("gamestart.ogg"));
            _sndMap[SoundEffect.GameOver] = new SoundBuffer(getPath("gameover.ogg"));
        }

I tried different things and found that app crash disappears when I call Sound.Play from the UI thread only and will not use it when it is still in Playing state.
So, probably this method isn't thread safe.

Also I found that there is some kind of bug. Sometimes it may crash app if I call it when it is still in playing state. I tried to execute Stop before action, but it didn't help. So I think it will be better to wait while playback will be completed.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Re: SFML stack overflow exception
« Reply #3 on: September 23, 2015, 08:15:35 am »
It may be minimal but no where near complete.

Yes, SFML is not thread-safe, so if you work with multiple threads you have to understand how to manage shared memory.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: SFML stack overflow exception
« Reply #4 on: September 24, 2015, 06:37:08 pm »