关于应用程序:由图块构造的自定义openGL map ,具有在基础 map 顶部绘制叠加层的功能。该应用程序适用于iPad和iPhone。
一些叠加是基于图块的,它们工作得很好。有些是由圆圈组成的,在 map 上的特定坐标处绘制。在圆上单击可打开一个带有关于 map 上该特定点的信息的弹出 View 。在iPhone库上,WEPopover用于实现类似于UIPopoverViewController的功能。
仅在iPhone和设备上会出现此问题。当叠加层包含大量圆圈时,打开带有信息的弹出 View 有时会导致叠加层闪烁,并最终在该行上发生EXC_BAD_ACCESS崩溃:glDrawArrays(GL_LINE_LOOP,0,360);
这只会在iPhone上发生,而不会在iPad或模拟器上发生。
一点点代码:
用白色轮廓绘制黑色圆圈:
for (int i = [pointsArray count]-1; i >= 0; i--) {
int pinColor = 0xffff0000;
static GLfloat vertices[720];
for (int i = 0; i < 720; i += 2) {
vertices[i] = (cos(DEGREES_TO_RADIANS(i)) * scale * 1.5);
vertices[i+1] = (sin(DEGREES_TO_RADIANS(i)) * scale * 1.5);
}
glVertexPointer(2, GL_FLOAT, 0, vertices);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
for (int dx = x0; dx <= x1; dx++)
{
glPushMatrix();
GLubyte a = (pinColor >> 24) & 0xff;
a = MIN((GLubyte) (opacity * 255), a);
glColor4ub(0, 0, 0, a);
GLfloat xx = point.x - centerX + dx * mapWidth;
xx *= zoom;
glTranslatef(xx, yy, 0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 360); <-----sometimes crash here
int color = 0xffffffff;
GLubyte n = (color >> 24) & 0xff;
GLubyte r = (color >> 16) & 0xff;
GLubyte g = (color >> 8) & 0xff;
GLubyte b = (color >> 0) & 0xff;
n = MIN((GLubyte) (opacity * 255), n);
glColor4ub(r,g,b,n);
glLineWidth(1);
glDrawArrays(GL_LINE_LOOP, 0, 360); <------crash here
glLineWidth(1);
glPopMatrix();
}
glDisable(GL_BLEND);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, 0);
}
在iPhone上打开弹出窗口:
WEPopoverController *_popover = [[WEPopoverController alloc] initWithContentViewController:pointDetails];
_popover.popoverContentSize = pointDetails.view.frame.size;
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
{
CGRect myrect2 = CGRectMake(xx,yy, 1, 1);
[_popover presentPopoverFromRect:myrect2 inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
CGRect myrect2 = CGRectMake(xx, yy, 1, 1);
[_popover presentPopoverFromRect:myrect2 inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
self.detailsPopIphone = _popover;
[_popover release];
每次触摸屏幕(缩放 map ,打开弹出窗口)都会重新渲染openGL map 。
我很乐意提供任何其他信息或代码。
最佳答案
解决了此问题。
问题在于,openGL的渲染与WEPopover的动画同时发生,这引起了冲突。按照渲染和动画接连发生的方式来组织代码,从而解决了该问题。
关于iphone - 打开WEPopover时EXC_BAD_ACCESS使glDrawArrays崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10251063/