<div dir="ltr">Hi Fabian,<div><br></div><div>Link-time optimisation should be fine - we do it on release builds with no problems. It's either something you've changed, or it's the static linking.</div><div><br></div><div>We still don't know exactly which version of OpenMW and OSG you've built, though. It's pretty obviously not the RC this thread is discussing if you're using an existing OpenMW release or something you got from the master branch with no local changes, as OpenMW literally won't build without unofficial changes yet. Can you get back to us with a specific answer?</div><div><br></div><div>Cheers,</div><div><br></div><div>Chris<br><br>On Tuesday, 28 January 2020 23:13:47 UTC, Fabian Roth  wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><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>==============================<wbr>==============================<wbr>=====<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::<wbr>ScopedPointerLock<OpenThreads:<wbr>:Mutex>::ScopedPointerLock(<wbr>OpenThreads::Mutex*) ./openmw/extern-git/<wbr>OpenSceneGraph/include/<wbr>OpenThreads/ScopedLock:54<br>    #1 0x5597ebadb5ab in addParent ./openmw/extern-git/<wbr>OpenSceneGraph/src/osg/<wbr>StateAttribute.cpp:31<br>    #2 0x5597ebadbc84 in setAttribute ./openmw/extern-git/<wbr>OpenSceneGraph/src/osg/<wbr>StateSet.cpp:1784<br>    #3 0x5597ebadc737 in osg::StateSet::<wbr>setAttributeAndModes(osg::<wbr>StateAttribute*, unsigned int) [clone .part.309] ./openmw/extern-git/<wbr>OpenSceneGraph/src/osg/<wbr>StateSet.cpp:1076<br>    #4 0x5597ebcb7241 in __base_ctor  ./openmw/extern-git/<wbr>OpenSceneGraph/src/osgUtil/<wbr>RenderBin.cpp:174<br>    #5 0x5597ebcb7a37 in __base_ctor  ./openmw/extern-git/<wbr>OpenSceneGraph/src/osgUtil/<wbr>RenderBin.cpp:37<br>    #6 0x5597ebcb7a37 in renderBinPrototypeList ./openmw/extern-git/<wbr>OpenSceneGraph/src/osgUtil/<wbr>RenderBin.cpp:53<br>    #7 0x5597eab5bacb in RenderBinSingletonProxy::<wbr>RenderBinSingletonProxy() ./openmw/extern-git/<wbr>OpenSceneGraph/src/osgUtil/<wbr>RenderBin.cpp:58<br>    #8 0x5597eab5bacb in __static_initialization_and_<wbr>destruction_0 ./openmw/extern-git/<wbr>OpenSceneGraph/src/osgUtil/<wbr>RenderBin.cpp:58<br>    #9 0x5597eab5bacb in _GLOBAL__sub_I__<wbr>ZN7osgUtil9RenderBin21getRende<wbr>rBinPrototypeERKNSt7__<wbr>cxx1112basic_stringIcSt11char_<wbr>traitsIcESaIcEEE.lto_priv.3181 ./openmw/extern-git/<wbr>OpenSceneGraph/src/osgUtil/<wbr>RenderBin.cpp:665<br>    #10 0x5597eabb1163 in global constructors keyed to 65535_0_objects.cpp.o.6481610 (./openmw-build/openmw+<wbr>0x3b5163)<br>    #11 0x5597ec775bcc in __libc_csu_init (./openmw-build/openmw+<wbr>0x1f79bcc)<br>    #12 0x7f213df67b27 in __libc_start_main (/lib/x86_64-linux-gnu/libc.<wbr>so.6+0x21b27)<br>    #13 0x5597eabe6039 in _start (./openmw-build/openmw+<wbr>0x3ea039)<br><br>AddressSanitizer can not provide additional info.<br>SUMMARY: AddressSanitizer: SEGV ./openmw/extern-git/<wbr>OpenSceneGraph/include/<wbr>OpenThreads/ScopedLock:54 in OpenThreads::<wbr>ScopedPointerLock<OpenThreads:<wbr>:Mutex>::ScopedPointerLock(<wbr>OpenThreads::Mutex*)<br>==19668==ABORTING<br> </div></div></blockquote></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/14ff71fc-b430-4ff5-a2a5-1bd3d2fc163e%40googlegroups.com?utm_medium=email&utm_source=footer">https://groups.google.com/d/msgid/osg-users/14ff71fc-b430-4ff5-a2a5-1bd3d2fc163e%40googlegroups.com</a>.<br />