cpl
cpl

Reputation: 689

Boost shared_ptr assert fails but the value is not NULL

in one of my applications I get an assert fail exception in the assert inside the boost shared_ptr dereference operator:

T * operator-> () const // never throws
{
    BOOST_ASSERT(px != 0); <------ fails!
    return px;
}

The problem is that using a debugger i see that the value of px is different from 0, something like 0x7ff.... ! Is such a situation possibile? How could the assert fail?

Thanks

Upvotes: 1

Views: 5349

Answers (1)

Daniel Gehriger
Daniel Gehriger

Reputation: 7468

As you say yourself, the assert isn't failing. Instead, an exception is being raised inside it. This is not the same.

My guess is that the boost::shared_ptr::px member points to an incorrect memory location, and it does so, because the boost::shared_ptr object itself is invalid.

For instance, is your boost::shared_ptr used as a member of some class? If so, check if the object is valid (is this valid, has it's memory been corrupted)?

Update:

Ok - after your clarification that the assert is indeed failing: are you ever assigning to mysocket or even calling mysocket.reset()?

Upvotes: 1

Related Questions