Crash after connection

Post here your questions about the C++ API for SFS2X

Moderators: Lapo, Bax, MBagnati

hainh
Posts: 4
Joined: 08 Dec 2012, 05:00

Crash after connection

Postby hainh » 16 Aug 2014, 05:37

I tried to connect to sfs through this code:

Code: Select all

void connectToSfs()
{
   smartfoxServer = boost::shared_ptr<Sfs2X::SmartFox>(new Sfs2X::SmartFox(true));
   smartfoxServer->ThreadSafeMode(true);
   //auto connectionEvtLtnr = boost::shared_ptr<Sfs2X::Util::EventListenerDelegate>(
   //   new Sfs2X::Util::EventListenerDelegate(onConnection, (unsigned long long(0))));
    //smartfoxServer->AddEventListener(SFSEvent::CONNECTION, connectionEvtLtnr);

   std::string cfFile = "sfs-config.xml";
   auto cf = cocos2d::FileUtils::getInstance()->fullPathForFilename(cfFile);
   smartfoxServer->LoadConfig(cf, true);
}


After LoadConfig called, I see SessionCreated in server console, in

Code: Select all

void SmartFox::LoadConfig(string filePath, bool connectOnSuccess)
after step over call

Code: Select all

configLoader->LoadConfig(filePath);
I made one more step then crash due to _BLOCK_TYPE_IS_VALID(pHead->nBlockUse), I searched for that and found that it seemed deleting a pointer more than once.

We've just started and got stuck :(
MBagnati
Posts: 126
Joined: 12 Feb 2013, 10:57

Re: Crash after connection

Postby MBagnati » 28 Aug 2014, 21:25

Hi,
I have tried to replicate the issue but unfortunately I have not seen any crash.

My test is made of a class declared in a .H file

Code: Select all

class CMyTest
{
public:
    void connectToSfs();

private:
   boost::shared_ptr<Sfs2X::SmartFox> smartfoxServer;
};

and implemented in a .cpp file

Code: Select all

void CMyTest::connectToSfs()
{
   smartfoxServer = boost::shared_ptr<Sfs2X::SmartFox>(new Sfs2X::SmartFox(true));
   smartfoxServer->ThreadSafeMode(true);

   std::string cfFile = ".\\Configuration\\sfs-config.xml";
   // I remove the below statement because I have not cocos2d
   // auto cf = cocos2d::FileUtils::getInstance()->fullPathForFilename(cfFile);
      smartfoxServer->LoadConfig(cfFile, true);
}


In connectToSfs method I have copied your code, removing only the call to cocos2d::FileUtils::getInstance()->fullPathForFilename
because I have not cocos2d at the moment on my Pc.
Instead of cocos2d::FileUtils::getInstance()->fullPathForFilename I have set the cfFile string with an appropriate value

Could you give me additional information about the call to connectToSfs method in your context where the crash occurs?
May be that in your context, the smartfoxServer smart pointer goes out of scope while LoadConfig is working?

Could you compare your code with our SimpleChat sample?
In SimpleChat sample you can see the declaration of a SmartFox pointer in MainFrm.h (at the end of the file)

Code: Select all

   boost::shared_ptr<Sfs2X::SmartFox> m_ptrSmartFox;


and the establishment of the connection with SmartFox Server in MainFrm.cpp

Code: Select all

void CMainFrame::InitializeSmartFox()
{
   // Initialize Smart Fox
   m_ptrSmartFox = boost::shared_ptr<Sfs2X::SmartFox>(new Sfs2X::SmartFox(true));
   m_ptrSmartFox->ThreadSafeMode(false);

   ...

   m_ptrSmartFox->LoadConfig(".\\Configuration\\sfs-config.xml", true);
}

Return to “SFS2X C++ API”

Who is online

Users browsing this forum: No registered users and 13 guests