I have failed EXC_ARM_DA_ALIGN in my application. Here is the code that the Xcode flag is "malignant." On the simulator, I do not have this failure, only on the device, so I think this is a memory alignment problem. Is there anyone who knows how to fix this code? Thank you very much.
-(int) Save:(void*) pBuf { int nNeedSize = sizeof(fType) + sizeof(sizeBrush) + sizeof(nBrushType) + sizeof(rcImage) + sizeof(count) + sizeof(data[0]) * count; if (pBuf == nil) return nNeedSize; *(NSInteger*)pBuf = count; pBuf += sizeof(count); *(BOOL*)pBuf = fType; pBuf += sizeof(fType); (*(CGSize*)pBuf).width = sizeBrush.width; (*(CGSize*)pBuf).height = sizeBrush.height; pBuf += sizeof(sizeBrush); *(NSInteger*)pBuf = nBrushType; pBuf += sizeof(nBrushType); (*(CGRect*)pBuf).size.width = rcImage.size.width; (*(CGRect*)pBuf).size.height = rcImage.size.height; (*(CGRect*)pBuf).origin.x = rcImage.origin.x; (*(CGRect*)pBuf).origin.y = rcImage.origin.y; pBuf += sizeof(rcImage); for (int i = 0; i < count; i++) { (*(CGPoint*)pBuf).x = data[i].x; (*(CGPoint*)pBuf).y = data[i].y; pBuf += sizeof(data[0]); } return nNeedSize;}
And here is another part marked as malignant:
int i; int nTotalSize = 0; for (i = 0; i < m_Data.count; i++) { maskStroke* one = [m_Data objectAtIndex:i]; nTotalSize += [one Save:NULL]; } unsigned char* buf = (unsigned char*)malloc(nTotalSize+100); unsigned char* cur_ptr = buf; for (i = 0; i < m_Data.count; i++) { maskStroke* one = [m_Data objectAtIndex:i]; cur_ptr += [one Save:cur_ptr]; }
source share