KhronosGroup / KhronosGroup/OpenCOLLADA

apple clang 7 / libc++: segfault in COLLADABU::IDList::addId

Open
#354 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
679
Forks
260
PR merge metrics
No merged PRs in 30d

Description

using apple clang 7 with libc++ on osx 10.11, i am observing a segfault in COLLADABU::IDList::addID in the mIdSet.insert call (line 34). this happens with -O0, -O1 or -O2. replacing the insert with emplace seems to help, but i do not understand the problem. according to the debugger, the state of mIDSet and the newIdChecked value are just fine before the crash. happy for any hints here...

compile flags:

```
cmake -G "Unix Makefiles" -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DCMAKE_C_FLAGS="-fPIC -fvisibility=hidden -fvisibility-inlines-hidden" -DCMAKE_CXX_FLAGS="-fPIC -std=c++11 -stdlib=libc++" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS_DEBUG="-O0 -g -DDEBUG" ...
```

my code looks like this:

```
namespace {
const std::string VISMAT = "VisualMaterial";
}

void ColladaEncoder::processMaterials(Context& ctx) {
//...
if(ctx.mIncludeMaterials) {
BOOST_FOREACH(const Context::ProcessedShapes& processedShapes, ctx.mProcessedShapesList) {
BOOST_FOREACH(const prtx::EncodePreparator::FinalizedInstance& instance, processedShapes.mFinalizedInstances) {
BOOST_FOREACH(const prtx::MaterialPtr& material, instance.getMaterials()) {
if(ctx.mMaterials.find(material) == ctx.mMaterials.end()) {
Context::MaterialInfo& mi = ctx.mMaterials.insert(std::make_pair(material, Context::MaterialInfo())).first->second;
mi.mMaterialId = ctx.materialIDList.addId(VISMAT);
}
}
}
}
} else {
// ...
```

the stacktrace:

```
#0 0x0000000109c51d04 in std::__1::__tree_node_base*& std::__1::__tree, std::__1::allocator >, std::__1::less, std::__1::allocator > >, std::__1::allocator, std::__1::allocator > > >::__find_equal, std::__1::allocator > >(std::__1::__tree_node_base*&, std::__1::basic_string, std::__1::allocator > const&) () from [redacted]
#1 0x0000000109c50ff2 in std::__1::__tree, std::__1::allocator >, std::__1::less, std::__1::allocator > >, std::__1::allocator, std::__1::allocator > > >::__insert_unique(std::__1::basic_string, std::__1::allocator > const&) ()
from [redacted]
#2 0x00000001091b26f8 in insert (this=0x10553d630, __v=...) at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/set:597
#3 COLLADABU::IDList::addId (this=0x10553d620, newId=..., returnConverted=true, alwaysAddNumberSuffix=false) at [redacted]/dev/git/OpenCOLLADA/COLLADABaseUtils/src/COLLADABUIDList.cpp:34
#
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in COLLADABaseUtils/src/COLLADABUIDList.cpp at line 34, where IDList::addId calls mIdSet.insert, and review the accompanying Apple Clang 7/libc++ stack trace. Reproduce the crash with the reported macOS 10.11 compiler and flags, then identify and correct the cause so addId no longer segfaults.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.