4

我一直在尝试解决此问题一段时间,但无法弄清楚它发生的原因。它似乎只在“存档”应用程序并在设备上运行时发生,而不是在调试应用程序时发生。

我有两节课:

@interface AppController : NSObject <UIApplicationDelegate>
{
    EAGLView * glView;  // A view for OpenGL ES rendering
}

@interface EAGLView : UIView
{
@public
    GLuint framebuffer;
}

- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)fformat depthFormat:(GLuint)depth stencilFormat:(GLuint)stencil preserveBackbuffer:(bool)retained scale:(float)fscale msaaMaxSamples:(GLuint)maxSamples;

我正在初始化一个对象:

glView = [ EAGLView alloc ];
glView = [ glView initWithFrame:rect pixelFormat:strColourFormat depthFormat:iDepthFormat stencilFormat:iStencilFormat preserveBackbuffer:NO scale:scale msaaMaxSamples:iMSAA ];
NSLog(@"%s:%d &glView %p\n", __FILE__, __LINE__, glView );
NSLog(@"%s:%d &glView->framebuffer %p\n", __FILE__, __LINE__, &glView->framebuffer );

initWithFrame 看起来像:

- (id) initWithFrame:(CGRect)frame
    /* ... */
{
    if( ( self = [super initWithFrame:frame] ) )
    {
        /* ... */
    }
    NSLog(@"%s:%d &self %p\n", __FILE__, __LINE__, self );
    NSLog(@"%s:%d &framebuffer %p\n", __FILE__, __LINE__, &framebuffer );

    return self;
}

日志显示:

EAGLView.mm:399 self 0x134503e90
EAGLView.mm:401 &framebuffer 0x134503f68
AppController.mm:277 glView 0x134503e90
AppController.mm:281 &glView->framebuffer 0x134503f10

当包含它的对象没有改变时,这个成员变量的地址怎么会改变呢?

4

1 回答 1

1

为什么不使用指针呢?您可以保证地址是相同的。将 EAGLView 修改为像

@interface EAGLView : UIView 
{ 
@public
    GLuint *framebuffer; 
}

打印出framebufferas的地址:

NSLog(@"%s:%d &glView->framebuffer %p\n", __FILE__, __LINE__, glView->framebuffer );

在里面initWithFrame做类似的事情:

- (id) initWithFrame:(CGRect)frame
{
    unsigned int fbo= opengl_get_framebuffer();
    framebuffer = &fbo;
    NSLog(@"%s:%d &framebuffer %p\n", __FILE__, __LINE__, framebuffer );
}

现在帧缓冲区的地址应该是一样的!

于 2013-11-01T17:22:57.023 回答