Jump to content
  • Advertisement
Sign in to follow this  
stodge

Problem with boost:smart_ptr - invalid pointer?

This topic is 4332 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using boost::smart_ptr and creating instances of a smart pointer in a tight loop. I create the object, use it and then delete it. I print out the pointer using std::cout and for the first 62 iterations, the value is always the same. On the 63rd iteration, the pointer value I see printed out is different. At this point my program crashes as the pointer dereferenced by the smart pointer is invalid. Is there some memory resource I'm exhausting here? It's coincidental it's always the same iteration that fails. I'm using Fedora Core 2 on GCC 3.3.3, but I've tested it with the same problem on PCLinuxOS, using GCC 4. I'd post some more code, but it's quite complex due to the class structure, so I'll try to pick and post bits out later if I have time. Thanks

Share this post


Link to post
Share on other sites
Advertisement
Maybe tight wasn't the right word!

		HBMessagePacketPtr pack = 
hbMessagePacketFactory::GetSingleton().
CreatePacket( hbProtocol::CMD_CHAT_SEND_MESSAGE,
hbMessagePacket::HB_RELIABLE &
hbMessagePacket::HB_ORDERED);
mConnection->Send(pack);

if (pack)
delete pack;



This is what's "in" the loop, but mConnection->Send(pack) invokes a whole bunch of code.....

So it's no help just posting this.

Share this post


Link to post
Share on other sites
First of all, you don't need "if (pack) delete pack". In C++ it's okay to delete a null pointer. What happens if you comment out the mConnection->Send(pack); line? Does it still crash the same way?

Share this post


Link to post
Share on other sites
Something must be trashing the stack -> now after a full rebuild, when I call:

mConnection->Send(pack);

The debugger actually goes into a completely object & function!

Share this post


Link to post
Share on other sites
Try stepping through the code line by line and watching the EBP and ESP registers in your debugger's register window. Whenever the values in those registers get too small, you are about to corrupt the stack.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!