0

关于应用程序:由瓷砖构建的自定义openGL地图,具有在底图顶部绘制叠加层的功能。该应用程序适用于 iPad 和 iPhone。一些覆盖是基于图块的,它们工作得很好。有些是由圆圈组成的,在地图上的特定坐标处绘制。单击一个圆圈会打开一个弹出视图,其中包含有关地图上该特定点的信息。在 iphone 库 WEPopover 上用于实现类似于 UIPopoverViewController 的功能。

该问题仅出现在 iphone 和设备上。当覆盖包含大量圆圈时,打开带有信息的弹出视图有时会导致覆盖闪烁并最终导致 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];    

每次触摸屏幕(移动缩放地图,打开弹出框)时,openGL 地图都会重新渲染。

我很乐意提供任何其他信息或代码。

4

1 回答 1

0

修复了这个问题。问题是openGL覆盖的渲染和WEPopover的动画同时发生,是什么导致了冲突。以渲染和动画依次发生的方式组织代码解决了问题。

于 2012-04-22T18:33:38.930 回答