Page 1 of 1

join room crash when ThreadSafeMode turn on

Posted: 07 May 2013, 03:52
by ganquan
i try to join the lobby room after login, code below:

Code: Select all

void FullHouseServer::init( )
{
	// Initialize Smart Fox
	mSmartFox = new SmartFox(true);
	mSmartFox->ThreadSafeMode(true);

	// Add event listeners
	mSmartFox->AddEventListener(SFSEvent::CONNECTION, new EventListenerDelegate(FullHouseServer::OnSmartFoxConnection, (void*)this));
	mSmartFox->AddEventListener(SFSEvent::CONNECTION_LOST, new EventListenerDelegate(FullHouseServer::OnSmartFoxConnectionLost, (void*)this));
	mSmartFox->AddEventListener(SFSEvent::LOGIN, new EventListenerDelegate(FullHouseServer::OnSmartFoxLogin, (void*)this));
	mSmartFox->AddEventListener(SFSEvent::LOGIN_ERROR, new EventListenerDelegate(FullHouseServer::OnSmartFoxLoginError, (void*)this));	
	mSmartFox->AddEventListener(SFSEvent::LOGOUT, new EventListenerDelegate(FullHouseServer::OnSmartFoxLogout, (void*)this));
	mSmartFox->AddEventListener(BitSwarmEvent::DISCONNECT, new EventListenerDelegate(FullHouseServer::OnSmartFoxDisconnection, (void*)this));

	mSmartFox->AddEventListener(SFSEvent::ROOM_JOIN, new EventListenerDelegate(FullHouseServer::OnSmartFoxRoomJoin, (void*)this));
	mSmartFox->AddEventListener(SFSEvent::ROOM_JOIN_ERROR, new EventListenerDelegate(FullHouseServer::OnSmartFoxRoomJoinError, (void*)this));

	//load config file, and connect
	std::string* filename = new std::string(".\\sfs-config.xml");
	mSmartFox->LoadConfig(filename, true);
	delete filename;
	filename = NULL;
}

void FullHouseServer::update( )
{
	//handle the message manually
	mSmartFox->ProcessEvents();
}

void FullHouseServer::OnSmartFoxConnection(void* ptrContext, BaseEvent* ptrEvent)
{
	//do nothing
}

void FullHouseServer::login( )
{
	//login zone when connect success
	std::string* stdUsername = new string("");
	std::string* stdPwd      = new string("");
	std::string* stdZoneName = new string("BasicExamples");
	// Perform login request
	LoginRequest* request = new LoginRequest(stdUsername, stdPwd, stdZoneName);
	mSmartFox->Send(request);
	delete request;
	request = NULL;
}

//join lobby
void FullHouseServer::joinLobby( )
{
	//join lobby
	std::string* ptrStdRoomName = new string("The Lobby"); 
	string * strPwd = new string("");
	JoinRoomRequest* request = new JoinRoomRequest(ptrStdRoomName,strPwd );
	mSmartFox->Send(request);
	delete request;
	request = NULL;
}
void FullHouseServer::OnSmartFoxRoomJoin(void* ptrContext, BaseEvent* ptrEvent)
{
	MessageBox(NULL,"SmartFox RoomJoin","FullHouseServer",MB_OK);
}
when ThreadSafeMode is true, call joinLobby to send request, it will crash after OnSmartFoxRoomJoin called, but not every time. Some time, it continue work.

and when i try to join the user to lobby in serve when he enter zone:

Code: Select all

public class zoneJoinEvent  extends BaseServerEventHandler
{
	public void handleServerEvent(ISFSEvent event) throws SFSException
	{
		User theUser = (User) event.getParameter(SFSEventParam.USER);
		
		// Join the user into the lobby
		Room lobby = getParentExtension().getParentZone().getRoomByName("The Lobby");
		
		if (lobby == null)
			throw new SFSException("The Lobby Room was not found!");
		
		getApi().joinRoom(theUser, lobby);
	}
}
the client will crash after login.

Re: join room crash when ThreadSafeMode turn on

Posted: 07 May 2013, 17:01
by Bax
We have updated the 0.9.5 package fixing a bug in the SmartFox.cpp file. This should correct the problem.
Can you please update your project and retest?
Thank you.