About the app: Custom openGL map constructed by tiles with function of drawing overlays on top of base map. The app is universal for both iPad and iPhone. Some overlays are tile based, which are working totally fine. Some are made of circles, drawn at particular coordinates on the map. Where clicking on a circle opens a popover view with information about this particular point on the map. On iphone library WEPopover used to implement functionality similar to UIPopoverViewController.
The problem occurs only on iphone and only on device. when overlay consist of large amount of circles, opening popover view with info sometimes causes a blink in the overlay and eventually EXC_BAD_ACCESS crash on the line: glDrawArrays(GL_LINE_LOOP, 0, 360); This only happens on iphone and never on ipad or simulator.
Little bit of code:
drawing black circles with white outline:
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);
}
Opening popover on 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];
every time you touch the screen (move scale the map, open popover) openGL map being re-rendered.
I will be happy to provide any additional information or code.