Fatal signal using std::set::insert()

Hi,

I am getting a Fatal signal with std::set::insert(). I’m really not sure what to
try next:

Here is my code:

std::cout << "max size: " << _indices.max_size() << std::endl;
std::cout << "size: " << _indices.size() << std::endl;
std::cout << "t._indices[0] " << t._indices[0] << std::endl;
_indices.insert(t._indices[0]);
std::cout << "max size: " << _indices.max_size() << std::endl;
std::cout << "size: " << _indices.size() << std::endl;
std::cout << "t._indices[1] " << t._indices[1] << std::endl;
_indices.insert(t._indices[1]);
std::cout << "max size: " << _indices.max_size() << std::endl;
std::cout << "size: " << _indices.size() << std::endl;
std::cout << "t._indices[2] " << t._indices[2] << std::endl;
_indices.insert(t._indices[2]);

When I run it I get:

max size: 4294967295
size: 56
t._indices[0] 206
max size: 4294967295
size: 56
t._indices[1] 212
Fatal signal: Segmentation Fault (SDL Parachute Deployed)

I changed my code to:
_indices.insert(t._indices[0]);
_indices.insert(t._indices[2]);
_indices.insert(t._indices[1]);

It inserted 2 ok but still failed on 1. Any ideas? How should I go about
debugging this?

-Jimmy

Hi,
I am getting a Fatal signal with std::set::insert(). I’m really not
sure what to
try next:

IThis is not the correct place to post C++ questions. Try usenet
(comp.lang.c++) next time.
Anyway - some suggestions on this:

Here is my code:

std::cout << "max size: " << _indices.max_size() << std::endl;
std::cout << "size: " << _indices.size() << std::endl;
std::cout << "t._indices[0] " << t._indices[0] << std::endl;
_indices.insert(t._indices[0]);
std::cout << "max size: " << _indices.max_size() << std::endl;
std::cout << "size: " << _indices.size() << std::endl;
std::cout << "t._indices[1] " << t._indices[1] << std::endl;
_indices.insert(t._indices[1]);
std::cout << "max size: " << _indices.max_size() << std::endl;
std::cout << "size: " << _indices.size() << std::endl;
std::cout << "t._indices[2] " << t._indices[2] << std::endl;
_indices.insert(t._indices[2]);

I guess t._indices is a set, too.

When I run it I get:

max size: 4294967295
size: 56
t._indices[0] 206
max size: 4294967295
size: 56
t._indices[1] 212
Fatal signal: Segmentation Fault (SDL Parachute Deployed)

It inserted 2 ok but still failed on 1. Any ideas? How should I go
about
debugging this?

Smells like t._indices[1] is tried to be accessed but does not exist.
If this t._indices is a set such things can happen, as (afair) a set
is stored (or better - suggested to be stored) as a binary tree so
maybe you’re trying to access an empty leaf here (some please correct
me if I’m wrong). What exactly happens depends on the STL-
Implementation you’re using.
If you use sets or maps I would strongly recommend to use iterators
or the find function to access elements. I would only trust the
bracket-operator when using vectors.

For more precise explainations on that topic I would have a look at
comp.lang.c++ as already mentioned.

ArneAm 27.06.2005 um 06:39 schrieb Jimmy: