Page MenuHome

glibc error when playing sound using BGE
Closed, ArchivedPublic

Description

I found a problem with sound which crashes blenderplayer. It feels like it happens when playing short sounds. We are using bge.

gdb backtrace:


[Thread 0xae456b70 (LWP 31219) exited]
[New Thread 0xae456b70 (LWP 31220)]
*** glibc detected *** /home/wcosta/work/blender-git/build/bin/blenderplayer: corrupted double-linked list: 0xad213a38 ***
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x6ff22)[0xb7491f22]
/lib/i386-linux-gnu/libc.so.6(+0x70d88)[0xb7492d88]
/lib/i386-linux-gnu/libc.so.6(cfree+0x6d)[0xb7495cad]
/usr/lib/i386-linux-gnu/libstdc++.so.6(_ZdlPv+0x1f)[0xb7d9b80f]
/home/wcosta/work/blender-git/build/bin/blenderplayer(_ZN11AUD_IHandleD0Ev+0x28)[0x934c708]
pure virtual method called
/home/wcosta/work/blender-git/build/bin/blenderplayer(_ZN13AUD_ReferenceIN16AUD_OpenALDevice16AUD_OpenALHandleEEaSERKS2_+0x50)terminate called without an active exception

Program received signal SIGABRT, Aborted.
0xb7fdf424 in __kernel_vsyscall ()
(gdb) bt
#0 0xb7fdf424 in __kernel_vsyscall ()
#1 0xb744fc8f in __GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#2 0xb74532b5 in __GI_abort () at abort.c:92
#3 0xb7d9f4ed in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#4 0xb7d9d283 in ?? () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#5 0xb7d9d2bf in std::terminate() () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#6 0xb7d9df32 in __cxa_pure_virtual () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#7 0x090134a6 in KX_SoundActuator::Update (this=0xbc69e50, curtime=287.05300000006764, frame=true)
at /home/wcosta/work/blender-git/blender/source/gameengine/Ketsji/KX_SoundActuator.cpp:171
#8 0x0907b92a in SCA_LogicManager::UpdateFrame (this=0xba4ed98, curtime=287.05300000006764, frame=true)
at /home/wcosta/work/blender-git/blender/source/gameengine/GameLogic/SCA_LogicManager.cpp:225
#9 0x0900ab03 in KX_Scene::LogicUpdateFrame (this=0xba48020, curtime=287.05300000006764, frame=true)
at /home/wcosta/work/blender-git/blender/source/gameengine/Ketsji/KX_Scene.cpp:1548
#10 0x08fcf941 in KX_KetsjiEngine::NextFrame (this=0xba46380) at /home/wcosta/work/blender-git/blender/source/gameengine/Ketsji/KX_KetsjiEngine.cpp:660
#11 0x08c833c2 in GPG_Application::processEvent (this=0xbfffe3d0, event=0xbc745c8)
at /home/wcosta/work/blender-git/blender/source/gameengine/GamePlayer/ghost/GPG_Application.cpp:481
#12 0x08ca2417 in GHOST_EventManager::dispatchEvent (this=0xb7faee0, event=0xbc745c8)
at /home/wcosta/work/blender-git/blender/intern/ghost/intern/GHOST_EventManager.cpp:116
#13 0x08ca24b8 in GHOST_EventManager::dispatchEvent (this=0xb7faee0) at /home/wcosta/work/blender-git/blender/intern/ghost/intern/GHOST_EventManager.cpp:133
#14 0x08ca2513 in GHOST_EventManager::dispatchEvents (this=0xb7faee0) at /home/wcosta/work/blender-git/blender/intern/ghost/intern/GHOST_EventManager.cpp:146
#15 0x08c9a3b6 in GHOST_System::dispatchEvents (this=0xb7eaf68) at /home/wcosta/work/blender-git/blender/intern/ghost/intern/GHOST_System.cpp:228
#16 0x08c812cb in main (argc=2, argv=0xbffff2c4) at /home/wcosta/work/blender-git/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp:973
(gdb) frame 7
#7 0x090134a6 in KX_SoundActuator::Update (this=0xbc69e50, curtime=287.05300000006764, frame=true)
at /home/wcosta/work/blender-git/blender/source/gameengine/Ketsji/KX_SoundActuator.cpp:171
171 bool isplaying = m_handle.isNull() ? false : (m_handle->getStatus() == AUD_STATUS_PLAYING);
(gdb)


I tried to run valgrind to detect where the error comes from, but unfortunately it does not happen under valgrind.

Blender version: 2.62.4.

Please find attached a dummy .blend file which reproduces the problem. Just run it with blenderplayer and after a while the problem shows up.

Thanks,
Wander Lairson Costa

Details

Type
To Do

Event Timeline

I couldn't get it to crash yet testing with Blender 2.63 rc1:
http://download.blender.org/release/Blender2.63/

The sounds files are not included though, so I had to insert my own. Maybe the particular sound files influence this, so it could help to include them. Probably it's a threading/timing issue

Oh, forgot the file were not embbeded, sorry. They are attached now.

@Wander,
Can you please check if it's still crashes for you using builds from http://download.blender.org/release/Blender2.63/
If so, does it crash only when using player or running form blender also leads to crash?

@Joerg,
Maybe you've got some clues here?

Hmm, tried to run it in blenderplayer 2.62 for 3 minutes and in 2.63 for 12 minutes, no crash.

Out from the backtrace, I cannot see where there's a "corrupted double-linked list" in "KX_SoundActuator.cpp:171".

I ran with 2.63 version, both blender and blenderplayer, the crash stills occurs.

Strange it is not happening for you, Joerg. In my computer, just a few minutes and blender goes down.

I have spent some time investigating it and it feels like a race condition in KX_SoundActuator::Update (KX_SoundActuator.cpp:155) and AUD_OpenALDevice::updateStreams (AUD_OpenALDevice.cpp:800).

If I understood correctly, m_handle is accessed when it has been deleted when the sounds stops in AUD_OpenALDevice::updateStreams, which would not make sense since the object is reference counted. Reviewing the AUD_Reference code, the reference counting mechanism seems not thread safe for me, so I re-implemented AUD_Reference using boost::shared_ptr, which provides thread safe reference counting. What happened is that with my AUD_Reference implementation, the problem shows up much faster (is this good or bad?), so I could run it under valgrind. Here is the valgrind output when the player crashes:

==3893== Invalid read of size 4
==3893== at 0x902FE20: KX_SoundActuator::Update(double, bool) (KX_SoundActuator.cpp:175)
==3893== by 0x9098E4D: SCA_LogicManager::UpdateFrame(double, bool) (SCA_LogicManager.cpp:225)
==3893== by 0x90272D6: KX_Scene::LogicUpdateFrame(double, bool) (KX_Scene.cpp:1548)
==3893== by 0x8FEC06C: KX_KetsjiEngine::NextFrame() (KX_KetsjiEngine.cpp:660)
==3893== by 0x8C9AB41: GPG_Application::processEvent(GHOST_IEvent*) (GPG_Application.cpp:481)
==3893== by 0x8CB9BA2: GHOST_EventManager::dispatchEvent(GHOST_IEvent*) (GHOST_EventManager.cpp:116)
==3893== by 0x8CB9C43: GHOST_EventManager::dispatchEvent() (GHOST_EventManager.cpp:133)
==3893== by 0x8CB9C9E: GHOST_EventManager::dispatchEvents() (GHOST_EventManager.cpp:146)
==3893== by 0x8CB1B41: GHOST_System::dispatchEvents() (GHOST_System.cpp:228)
==3893== by 0x8C98A4A: main (GPG_ghost.cpp:973)
==3893== Address 0x132fce78 is 0 bytes inside a block of size 112 free'd
==3893== at 0x4027919: operator delete(void*) (vg_replace_malloc.c:387)
==3893== by 0x9382487: AUD_OpenALDevice::AUD_OpenALHandle::~AUD_OpenALHandle() (AUD_OpenALDevice.h:110)
==3893== by 0x9383403: void boost::checked_delete<AUD_OpenALDevice::AUD_OpenALHandle>(AUD_OpenALDevice::AUD_OpenALHandle*) (checked_delete.hpp:34)
==3893== by 0x9383729: boost::detail::sp_counted_impl_p<AUD_OpenALDevice::AUD_OpenALHandle>::dispose() (sp_counted_impl.hpp:78)
==3893== by 0x8FAA861: boost::detail::sp_counted_base::release() (sp_counted_base_gcc_x86.hpp:145)
==3893== by 0x8FAA8F3: boost::detail::shared_count::~shared_count() (shared_count.hpp:217)
==3893== by 0x93824D1: boost::shared_ptr<AUD_OpenALDevice::AUD_OpenALHandle>::~shared_ptr() (shared_ptr.hpp:168)
==3893== by 0x9382C22: boost::shared_ptr<AUD_OpenALDevice::AUD_OpenALHandle>::reset() (shared_ptr.hpp:386)
==3893== by 0x938255E: AUD_Reference<AUD_OpenALDevice::AUD_OpenALHandle>::~AUD_Reference() (AUD_Reference.h:62)
==3893== by 0x937F176: AUD_OpenALDevice::AUD_OpenALHandle::stop() (AUD_OpenALDevice.cpp:181)
==3893== by 0x9380F83: AUD_OpenALDevice::updateStreams() (AUD_OpenALDevice.cpp:937)
==3893== by 0x9380735: AUD_openalRunThread(void*) (AUD_OpenALDevice.cpp:773)

Regards,
Wander Lairson Costa.

This error in valgrind is unrelated to the original problem. I just confirmed that. It is not possible to implement AUD_Reference by boost::shared_ptr because of the way reference count is implemented.

In AUD_Reference, a raw pointer associated to a instance of AUD_Reference can be used to create another unrelated AUD_Reference object, with reference counting being updated, this is not possible with shared_ptr.

I uploaded a patch [1] which is supposed to fix the bug.

[1] http://projects.blender.org/tracker/index.php?func=detail&aid=31130&group_id=9&atid=127

I have noticed this bug too, but didn't know what was causing it. Sometimes, when playing my game, Blender would crash with:

pure virtual method called
terminate called without an active exception

I think that does usually happen when a sound is played. But because I wasn't using a debug build, I got no stack trace. I have Blender built locally too, but I can't seem to get it to play sound through my custom builds, even though I have these settings:

WITH_AUDASPACE = ON
WITH_OPENAL = ON

Any suggestions for getting sound working in my builds? If so, I can test this new patch.

I have also tried the test file attached to this report in a recent build (from Ubuntu PPA), but it hasn't crashed for me yet, either.

Hi! Thanks for your patch and your help, I've committed to revision 46036, but I recoded it to use pthread mutexes to stay consistent with the currently used mutexes. Can you check if that commit fixes the problem?

Alex: you need at least either ffmpeg, libsndfile to be able to load sound files.

Sorry for the delay, I have been out of office these days. Tested and everything is ok.

Actually I found a issue, after reporting things were ok, I detected a deadlock when leaving the application. I am investigating it...

I submitted a new patch [1] which hopefully fixes the issue.

[1] http://projects.blender.org/tracker/index.php?func=detail&aid=31240&group_id=9&atid=127

Committed your patch, see comments there.

Joerg Mueller (nexyon) closed this task as Archived.May 5 2012, 1:39 AM