When debugging my code, I put a break point at this line:

std::set<unsigned int>::iterator it;

When I step over that line, I get "Debugger reported the following error: cannot access memory at address 0x10".

I am using KDevelop that ships with Fedora 11.

I've used that line of code many many times, so it doesn't make sense that it wouldn't work now..?

Does anyone have any idea what could be wrong?

Thanks,

Dave

Recommended Answers

All 8 Replies

Show more code.

Unfortunately this is embedded way way way in a huge project. I was trying to see if anyone could offer an "of course I can't be sure, but you could try XYZ".

Dave

I guess it was a gdb bug? I compiled the latest svn and it gets past that line now with no problems.

I guess it was a gdb bug? I compiled the latest svn and it gets past that line now with no problems.

Or it's undefined behavior, which will run in 99% of the cases (for example) and crash in 1%.
Show the line of code directly after the line you've posted.
- Are you checking if the std::set != NULL before you try to access it?
- Is the set being used in more then 1 thread?

Here is the next line:

std::set<unsigned int>::iterator it;
it = this->SubmeshVertexSet.find(MeshOriginIndex);

SubmeshVertexSet is a member variable:

private:
std::set<unsigned int> SubmeshVertexSet;

so there should not be a problem with it being null, right? In the worst case the find operation should just fail if the set is empty, right?

And why would it crash on the iterator declaration line rather than the line that is potentially actually causing the problem?

Dave

so there should not be a problem with it being null, right? In the worst case the find operation should just fail if the set is empty, right?

Correct. Find should return std::end if nothing is found.

And why would it crash on the iterator declaration line rather than the line that is potentially actually causing the problem?

That, I don't know. One thing I can imagine is that the this pointer has become invalid. This could happen if you destroy the class pointer in another thread for example. Why do you need the this pointer?

The thing is, I didn't change anything except the debugger and all is well, so I don't think the this pointer could be invalid and it work now?

I have to use the this pointer because of this:
http://www.daniweb.com/forums/thread223239.html

Apparently it doesn't understand the scope (even though I really thought it should?) without it.

Dave

It could be a glitch in GDB, but I would still go with corrupt pointers. What does the backtrace of GDB tell you?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.