No idea what this means...[Boost/Raknet]

Started by
5 comments, last by Maxamor 16 years, 3 months ago
I'm writing an online game using Raknet. But after a few loops around the game loop I get this weird asset error and I have no idea what is causing it. Debug Assertion Failed File: dbgdel.cpp Line: 52 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) This is where the error occurs, it stops when I comment this section out


			boost::shared_ptr<Packet> packet ( m_networkManager->getPackets() );

			if( packet.get() )
			{
				switch( packet->data[0] )
				{
				case ID_REMOTE_DISCONNECTION_NOTIFICATION:
					// Client disconnected
					logger.write( "Client disconnected" );	
					break;

				case ID_CONNECTION_REQUEST_ACCEPTED:
					logger.write( "We have connected" );
					break;
				
				case ID_NO_FREE_INCOMING_CONNECTIONS:
					logger.write( "Server is full" );
					break;

				case ID_REMOTE_CONNECTION_LOST:
					// Client lost connection
					logger.write( "Client lost connection" );
					break;

				case ID_REMOTE_NEW_INCOMING_CONNECTION:
					// New client connected
					logger.write( "Client Connected" );
					break;

				default:
					// Unhandled Packet
					logger.write( boost::format( "Unhandled Packet" ) );
					break;
				}
				m_networkManager->deletePacket( packet );
				
			}

The network manager...

	NetworkManager::NetworkManager()
	{
		logger.write( "Initializing the network manager..." );
		boost::shared_ptr<RakPeerInterface> peer( RakNetworkFactory::GetRakPeerInterface() );
		m_peer = peer;
	}

	NetworkManager::~NetworkManager()
	{
		
	}

	bool NetworkManager::startConnection( const std::string& ip, int port )
	{
		m_peer->Startup( 1, 30, &SocketDescriptor(), 1 );
		m_peer->Connect( ip.c_str(), port, 0, 0 );
		
		if( m_peer->IsActive() )
			logger.write( "Connected to server" );
		return true;
	}

	void NetworkManager::endConnection()
	{
		RakNetworkFactory::DestroyRakPeerInterface( m_peer.get() );
	}

	boost::shared_ptr<Packet> NetworkManager::getPackets()
	{
		boost::shared_ptr<Packet> packet( m_peer->Receive() );

		return packet;
	}

	void NetworkManager::deletePacket( boost::shared_ptr<Packet> packet )
	{
		m_peer->DeallocatePacket( packet.get() );
	}



Advertisement
It means you clobbered memory (buffer overrun), or maybe you tried to double-delete something. The code posted is of no use in solving the problem I'm afraid.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
Ok...I just commented out that selection in the game loop to see what happens again. Now I get an error after the return of main()...a problem with boost deleting a pointer. What is the best way to track this down?
I'm not familiar with RakNet, but I'm curious about this:
...RakNetworkFactory::GetRakPeerInterface()...
I gather this returns a pointer, but who owns it?

I ask because with some similar APIs (such as SDL), you sometimes acquire pointers to things that you do not in fact own. If that's the case here, then storing the retrieved pointer in a boost::shared_ptr object will probably not end well. (I can't say for sure that that's what's going wrong, but it might at least be worth looking into...)
Ok, I removed the smart pointers from the Raknet stuff, and everything works now. Thanks for the help.
Quote:Original post by Stormtrooper
Ok, I removed the smart pointers from the Raknet stuff, and everything works now. Thanks for the help.


I hope you didn't just do that blindly! Even though delete-ion is potentially bad with this API, it doesn't exclude the possibility that there exists a clean-up function that needs to be called. You could be leaking resources.

Did you check?
Did you check out the possibility that this:
boost::shared_ptr<Packet> packet ( m_networkManager->getPackets() );
could be trying to construct a NULL shared_ptr?

Nevermind. This shouldn't matter.

[Edited by - Maxamor on January 6, 2008 6:34:56 PM]

This topic is closed to new replies.

Advertisement