M
mblome
Hi everybody!
I came across a very strange problem with stl vectors during
developement of a mesh creation program. As the program is quite large
I can only post small parts of it. Basically I have a
std::vector<SPoly> xtop;
where SPoly simply is:
struct SPoly
{
int start, end;
int bmarker;
};
In my function (code reduced):
void MeshModel::createDomain()
{
std::vector<SPoly> xtop;
std::vector<NPoint> trinodes;
// lots of code, left out
// filling of xtop via repeated calls to xtop.push_back()
sortlist(xtop,trinodes);
// some other code, no changes to xtop
}
where sortlist is defined as:
void MeshModel::sortlist(std::vector<SPoly> &polies,
std::vector<NPoint> nodes)
{
// simple selection sort
int n=polies.size(); int m=nodes.size();
for(int i=0; i<n; i++)
{
int imin = i;
for(int j=i; j<n; j++)
{
assert(polies[imin].start < m); assert(polies[j].start < m);
if (nodes[polies[imin].start].point.y <
nodes[polies[j].start].point.y)
imin = j;
}
SPoly temp=polies;
polies=polies[imin];
polies[imin]=temp;
}
}
at the last line of createDomain() I get a segmentation fault. Here the
backtrace from gdb:
----------------------------------------------------------------------
#0 0x40181057 in _int_free () from /lib/tls/libc.so.6
#1 0x40180048 in free () from /lib/tls/libc.so.6
#2 0x400bb233 in operator delete () from /usr/lib/libstdc++.so.5
#3 0x400a8dac in std::__default_alloc_template<true, 0>::deallocate ()
from /usr/lib/libstdc++.so.5
#4 0x0804aa8d in std::__simple_alloc<SPoly,
std::__default_alloc_template<true, 0> >::deallocate (
__p=0x80982d8, __n=32) at
/usr/include/c++/3.2.3/bits/stl_alloc.h:248
#5 0x0804aa08 in std::_Vector_alloc_base<SPoly, std::allocator<SPoly>,
true>::_M_deallocate (
this=0xfff93ca0, __p=0x80982d8, __n=32) at
/usr/include/c++/3.2.3/bits/stl_vector.h:123
#6 0x0804a990 in ~_Vector_base (this=0xfff93ca0) at
/usr/include/c++/3.2.3/bits/stl_vector.h:143
#7 0x0804a90a in ~vector (this=0xfff93ca0) at
/usr/include/c++/3.2.3/bits/stl_vector.h:375
#8 0x08055054 in MeshModel::createDomain (this=0x8081008) at
tetmesh.cpp:1021
#9 0x08049ff9 in main () at dcfemeshseries.cpp:66
----------------------------------------------------------------------
Why does the destrucion of the variable xtop fail ? I also changed the
struct into a class with appropriately defined assignment operator,
copy constructor and destructor (why should this be necessary?) - still
the same segm. fault!
I am lost here! Any help on this would be great!
Mark
I came across a very strange problem with stl vectors during
developement of a mesh creation program. As the program is quite large
I can only post small parts of it. Basically I have a
std::vector<SPoly> xtop;
where SPoly simply is:
struct SPoly
{
int start, end;
int bmarker;
};
In my function (code reduced):
void MeshModel::createDomain()
{
std::vector<SPoly> xtop;
std::vector<NPoint> trinodes;
// lots of code, left out
// filling of xtop via repeated calls to xtop.push_back()
sortlist(xtop,trinodes);
// some other code, no changes to xtop
}
where sortlist is defined as:
void MeshModel::sortlist(std::vector<SPoly> &polies,
std::vector<NPoint> nodes)
{
// simple selection sort
int n=polies.size(); int m=nodes.size();
for(int i=0; i<n; i++)
{
int imin = i;
for(int j=i; j<n; j++)
{
assert(polies[imin].start < m); assert(polies[j].start < m);
if (nodes[polies[imin].start].point.y <
nodes[polies[j].start].point.y)
imin = j;
}
SPoly temp=polies;
polies=polies[imin];
polies[imin]=temp;
}
}
at the last line of createDomain() I get a segmentation fault. Here the
backtrace from gdb:
----------------------------------------------------------------------
#0 0x40181057 in _int_free () from /lib/tls/libc.so.6
#1 0x40180048 in free () from /lib/tls/libc.so.6
#2 0x400bb233 in operator delete () from /usr/lib/libstdc++.so.5
#3 0x400a8dac in std::__default_alloc_template<true, 0>::deallocate ()
from /usr/lib/libstdc++.so.5
#4 0x0804aa8d in std::__simple_alloc<SPoly,
std::__default_alloc_template<true, 0> >::deallocate (
__p=0x80982d8, __n=32) at
/usr/include/c++/3.2.3/bits/stl_alloc.h:248
#5 0x0804aa08 in std::_Vector_alloc_base<SPoly, std::allocator<SPoly>,
true>::_M_deallocate (
this=0xfff93ca0, __p=0x80982d8, __n=32) at
/usr/include/c++/3.2.3/bits/stl_vector.h:123
#6 0x0804a990 in ~_Vector_base (this=0xfff93ca0) at
/usr/include/c++/3.2.3/bits/stl_vector.h:143
#7 0x0804a90a in ~vector (this=0xfff93ca0) at
/usr/include/c++/3.2.3/bits/stl_vector.h:375
#8 0x08055054 in MeshModel::createDomain (this=0x8081008) at
tetmesh.cpp:1021
#9 0x08049ff9 in main () at dcfemeshseries.cpp:66
----------------------------------------------------------------------
Why does the destrucion of the variable xtop fail ? I also changed the
struct into a class with appropriately defined assignment operator,
copy constructor and destructor (why should this be necessary?) - still
the same segm. fault!
I am lost here! Any help on this would be great!
Mark