please help - seg fault in std::set

J

jimmy

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
 
A

Alan Johnson

jimmy said:
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

We need to see at least the declaration and initialization of "t" and
"_indices" (symbols beginning with an underscore are reserved for the
implementation, btw). A compilable subset of the program would be
preferable.

What happens if you leave out the inserts and just try:
std::cout << t._indices[0] << std::endl;
std::cout << t._indices[2] << std::endl;
std::cout << t._indices[1] << std::endl;

Also, if "t._indices" is a vector, what happens with:
std::cout << t._indices.at(0) << std::endl;
std::cout << t._indices.at(2) << std::endl;
std::cout << t._indices.at(1) << std::endl;

-Alan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,296
Messages
2,571,535
Members
48,281
Latest member
DaneLxa72

Latest Threads

Top