add m_pAccelDelegate != NULL to avoid crash

This commit is contained in:
dumganhar 2011-10-10 10:24:52 +08:00
parent eb9cb31ca4
commit f162a5fcaa
1 changed files with 5 additions and 2 deletions

View File

@ -55,7 +55,7 @@ CCAccelerometer* CCAccelerometer::sharedAccelerometer()
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
{
m_pAccelDelegate = pDelegate;
if (pDelegate)
if (pDelegate != NULL)
{
setEnable(true);
}
@ -82,7 +82,10 @@ void CCAccelerometer::OnDataReceived(SensorType sensorType, SensorData& sensorDa
AccValue.z = -z;
AccValue.timestamp = timeStamp;
m_pAccelDelegate->didAccelerate(&AccValue);
if (m_pAccelDelegate != NULL)
{
m_pAccelDelegate->didAccelerate(&AccValue);
}
AppLog("##TimeStamp:[%d], Accel.x,y,z:[%f,%f,%f]", timeStamp, x, y, z);
}