I discovered where is the problem but I still don't know what is the problem (I think it has something to do with CBufFlat). Maybe someone can help. I'll try to explain what happens.
The program uses an active object to detect some GPS position change (in RunL()) which in turn calls my AddLogL() function (here is where the problem is).
In the same program I have another active object that continuosly scans the wireless networks using WLAN Info API. In the RunL function I get the WLAN information and store it in a TBuf:
Code:
void CWLANInfo::RunL()
{
...
iWLANMgmtClient->GetScanResults(*iScanInfo);
CopyWLANInfo();
...
}
void CWLANInfo::CopyWLANInfo()
{
... //some code here that puts information from iScanInfo like:
iWLANBuf.Append(KXMLWLANStrengthTag);
TInt8 rxLevel = iScanInfo->RXLevel();
...
iWLANTempBuf.Copy(iWLANBuf);
}
Now in the AddLog() function I call a function(GetWLANInfo) that returns the data from iWLANTempBuf:
Code:
void CNetworkEngine::AddLogL(TReal aLatitude, TReal aLongitude)
{
CBufFlat *buf = CBufFlat::NewL(2);
CleanupStack::PushL(buf);
TBuf<1024> data;
HBufC8 *dataPtr;
buf->Reset();
buf->InsertL(0, KXMLInfoTag);
//Insert GPS Information
TBuf8<36> glat, glon;
TRealFormat rFormat(20, 10);
glat.Num(aLatitude, rFormat);
glon.Num(aLongitude, rFormat);
buf->InsertL(buf->Size(), KXMLGPSTag);
buf->InsertL(buf->Size(), KXMLLatitudeTag);
buf->InsertL(buf->Size(), glat);
buf->InsertL(buf->Size(), KXMLLatitudeEndTag);
buf->InsertL(buf->Size(), KXMLLongitudeTag);
buf->InsertL(buf->Size(), glon);
buf->InsertL(buf->Size(), KXMLLongitudeEndTag);
buf->InsertL(buf->Size(), KXMLGPSEndTag);
if(iWLANInfo)
{
//Insert WLAN Information
buf->InsertL(buf->Size(), KXMLWLANTag);
iWLANInfo->GetWLANInfo(data);
if(iNetworkEngineObserver)
iNetworkEngineObserver->HandleWLANMessageL(data);
// dataPtr = SenXmlUtils::ToUtf8LC(data);
// buf->InsertL(buf->Size(), dataPtr->Des());
// CleanupStack::PopAndDestroy(dataPtr);
// dataPtr = NULL;
buf->InsertL(buf->Size(), KXMLWLANEndTag);
}
if(iGSMInfo)
{
//Insert GSM Information
buf->InsertL(buf->Size(), KXMLGSMTag);
GetGSMInfoParsedL(data);
dataPtr = SenXmlUtils::ToUtf8LC(data);
buf->InsertL(buf->Size(), dataPtr->Des());
CleanupStack::PopAndDestroy(dataPtr);
dataPtr = NULL;
buf->InsertL(buf->Size(), KXMLGSMEndTag);
}
buf->InsertL(buf->Size(), KXMLInfoEndTag);
iFileLogger->Write(buf->Ptr(0));
buf->Reset();
CleanupStack::PopAndDestroy(buf);
}
The problem is on the commented red lines, when I try to use the information obtained from the GetWLANInfo function and add it to the CBufFlat object. As it can be seen I can use the data and display it (on the HandleWLANMessageL function).
If I uncomment the commented red lines I get the old problem: application exits without any panic or error code, or phone crashes and restarts.
It is very strange because I am using the same procedure(as you can see in the code) for the iGSMInfo object (which is another Active object that retrieves GSM information) and it works great with that.