<div dir="ltr"><br><br>On Tuesday, January 28, 2020 at 10:11:49 AM UTC+1, OpenSceneGraph Users wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir="ltr"><div dir="ltr">Hi Fabian,<br></div> <div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">My build is using static osg, static osg-plugins and link time optimization.<div>I created an address sanitizer enabled build.</div><div>It exhibits a heap-use-after-free.<br></div>I will try to further investigate this week.<br><div><br></div><div>==============================<wbr>==============================<wbr>=====<br>==11872==ERROR: AddressSanitizer: heap-use-after-free on address 0x6030000082c0 at pc 0x55b4b9659551 bp 0x7ffdf8a9c190 sp 0x7ffdf8a9c180<br>READ of size 8 at 0x6030000082c0 thread T0<br> #0 0x55b4b9659550 in OpenThreads::<wbr>ScopedPointerLock<OpenThreads:<wbr>:Mutex>::ScopedPointerLock(<wbr>OpenThreads::Mutex*) ./openmw/extern-git/<wbr>OpenSceneGraph/include/<wbr>OpenThreads/ScopedLock:54<br> #1 0x55b4b9659550 in osg::StateAttribute::<wbr>removeParent(osg::StateSet*) ./openmw/extern-git/<wbr>OpenSceneGraph/src/osg/<wbr>StateAttribute.cpp:38<br> #2 0x55b4b965a033 in osg::StateSet::clear() ./openmw/extern-git/<wbr>OpenSceneGraph/src/osg/<wbr>StateSet.cpp:734<br></div></div></blockquote><div><br></div><div>Given the stack trace it kinda looks like the getRefMutex() call in StateAttribute.cpp is the where things might be going astray (note the comment I've added below):</div><div><br></div><div>void StateAttribute::removeParent(<wbr>osg::StateSet* object)<br>{<br> OpenThreads::<wbr>ScopedPointerLock<OpenThreads:<wbr>:Mutex> lock(getRefMutex()); // calls the base classes Referenced::getRefMutex() method that will map to Referenced::<wbr>getGlobalReferencedMutex<br><br> ParentList::iterator pitr = std::find(_parents.begin(),_<wbr>parents.end(),object);<br> if (pitr!=_parents.end()) _parents.erase(pitr);<br>}</div><div><br></div><div>The Referenced::<wbr>getGlobalReferencedMutex() implementation in Referenced.cpp is:</div><div><br></div><div>OpenThreads::Mutex* Referenced::<wbr>getGlobalReferencedMutex()<br>{<br> static GlobalMutexPointer s_ReferencedGlobalMutext = new OpenThreads::Mutex;<br> return s_ReferencedGlobalMutext.get()<wbr>;<br>}<br><br>// helper class for forcing the global mutex to be constructed when the library is loaded.<br>struct InitGlobalMutexes<br>{<br> InitGlobalMutexes()<br> {<br> Referenced::<wbr>getGlobalReferencedMutex();<br> }<br>};<br>static InitGlobalMutexes s_initGlobalMutexes;</div><div><br></div><div>Which is all a bit hacky way of trying to get a singleton's _ReferencedGlobalMutext to construct before any other code calling getGlobalReferencedMutex() gets called.</div><div><br></div><div>I don't really know why a pointer is even being used here, it's not how I'd write the code these days, but off the top of my head don't recall the derivation and motivations between all this code as it dates back to the earliest days of the OSG project, so almost two decades :-)</div><div><br></div><div>What I'd write today would simply be:<br></div><div><br></div><div>static OpenThreads::Mutex s_ReferencedGlobalMutex;<br>OpenThreads::Mutex* Referenced::<wbr>getGlobalReferencedMutex()<br>{<br> return &s_ReferencedGlobalMutex;<br>}</div><div><br></div><div>You could try substituting this in. I will try a build here just to make sure the above works fine for standard OSG work. I don't expect this change to have any affect on your own code, if it does it suggest there is some issue with order of clean up of statics.<br></div><div><br></div><div>Robert.<br></div></div></div></blockquote><div><br></div><div>Hi Robert,</div><div>Using your suggested changes i get a crash on start.</div><div>I forgot to mention i also link OpenThreads statically.<br></div><div>I am starting to suspect the static linking and optimization surfaces undefined behavior.</div><div><br></div><div>Greetings,</div><div>Fabian<br></div><div><br></div><div>ASAN:DEADLYSIGNAL<br>=================================================================<br>==19668==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000010 (pc 0x5597ebadb5ac bp 0x60c000000b80 sp 0x7ffce8efbba0 T0)<br>==19668==The signal is caused by a READ memory access.<br>==19668==Hint: address points to the zero page.<br> #0 0x5597ebadb5ab in OpenThreads::ScopedPointerLock<OpenThreads::Mutex>::ScopedPointerLock(OpenThreads::Mutex*) ./openmw/extern-git/OpenSceneGraph/include/OpenThreads/ScopedLock:54<br> #1 0x5597ebadb5ab in addParent ./openmw/extern-git/OpenSceneGraph/src/osg/StateAttribute.cpp:31<br> #2 0x5597ebadbc84 in setAttribute ./openmw/extern-git/OpenSceneGraph/src/osg/StateSet.cpp:1784<br> #3 0x5597ebadc737 in osg::StateSet::setAttributeAndModes(osg::StateAttribute*, unsigned int) [clone .part.309] ./openmw/extern-git/OpenSceneGraph/src/osg/StateSet.cpp:1076<br> #4 0x5597ebcb7241 in __base_ctor ./openmw/extern-git/OpenSceneGraph/src/osgUtil/RenderBin.cpp:174<br> #5 0x5597ebcb7a37 in __base_ctor ./openmw/extern-git/OpenSceneGraph/src/osgUtil/RenderBin.cpp:37<br> #6 0x5597ebcb7a37 in renderBinPrototypeList ./openmw/extern-git/OpenSceneGraph/src/osgUtil/RenderBin.cpp:53<br> #7 0x5597eab5bacb in RenderBinSingletonProxy::RenderBinSingletonProxy() ./openmw/extern-git/OpenSceneGraph/src/osgUtil/RenderBin.cpp:58<br> #8 0x5597eab5bacb in __static_initialization_and_destruction_0 ./openmw/extern-git/OpenSceneGraph/src/osgUtil/RenderBin.cpp:58<br> #9 0x5597eab5bacb in _GLOBAL__sub_I__ZN7osgUtil9RenderBin21getRenderBinPrototypeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE.lto_priv.3181 ./openmw/extern-git/OpenSceneGraph/src/osgUtil/RenderBin.cpp:665<br> #10 0x5597eabb1163 in global constructors keyed to 65535_0_objects.cpp.o.6481610 (./openmw-build/openmw+0x3b5163)<br> #11 0x5597ec775bcc in __libc_csu_init (./openmw-build/openmw+0x1f79bcc)<br> #12 0x7f213df67b27 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b27)<br> #13 0x5597eabe6039 in _start (./openmw-build/openmw+0x3ea039)<br><br>AddressSanitizer can not provide additional info.<br>SUMMARY: AddressSanitizer: SEGV ./openmw/extern-git/OpenSceneGraph/include/OpenThreads/ScopedLock:54 in OpenThreads::ScopedPointerLock<OpenThreads::Mutex>::ScopedPointerLock(OpenThreads::Mutex*)<br>==19668==ABORTING<br> </div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:osg-users+unsubscribe@googlegroups.com">osg-users+unsubscribe@googlegroups.com</a>.<br />
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/osg-users/ee701728-f7f9-423d-a491-22083995288d%40googlegroups.com?utm_medium=email&utm_source=footer">https://groups.google.com/d/msgid/osg-users/ee701728-f7f9-423d-a491-22083995288d%40googlegroups.com</a>.<br />