c – 当包含它的对象不在时,该成员变量的地址如何在objective-c
发布时间:2020-12-14 17:22:44 所属栏目:百科 来源:网络整理
导读:我一直试图解决这个问题一段时间,但无法弄清楚它为什么会发生.它似乎只发生在“存档”应用程序并在设备上运行时,而不是在调试应用程序时. 我有两节课: @interface AppController : NSObject UIApplicationDelegate{ EAGLView * glView; // A view for OpenG
我一直试图解决这个问题一段时间,但无法弄清楚它为什么会发生.它似乎只发生在“存档”应用程序并在设备上运行时,而不是在调试应用程序时.
我有两节课: @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 %pn",__FILE__,__LINE__,glView ); NSLog(@"%s:%d &glView->framebuffer %pn",&glView->framebuffer ); 使用initWithFrame看起来像: - (id) initWithFrame:(CGRect)frame /* ... */ { if( ( self = [super initWithFrame:frame] ) ) { /* ... */ } NSLog(@"%s:%d &self %pn",self ); NSLog(@"%s:%d &framebuffer %pn",&framebuffer ); return self; } 日志显示: EAGLView.mm:399 self 0x134503e90 EAGLView.mm:401 &framebuffer 0x134503f68 AppController.mm:277 glView 0x134503e90 AppController.mm:281 &glView->framebuffer 0x134503f10 当包含它的对象没有时,该成员变量的地址如何变化? 解决方法
为什么不使用指针呢?保证地址是一样的.修改EAGLView就好
@interface EAGLView : UIView { @public GLuint *framebuffer; } 将framebuffer的地址打印出来: NSLog(@"%s:%d &glView->framebuffer %pn",glView->framebuffer ); 在initWithFrame里面做类似的事情: - (id) initWithFrame:(CGRect)frame { unsigned int fbo= opengl_get_framebuffer(); framebuffer = &fbo; NSLog(@"%s:%d &framebuffer %pn",framebuffer ); } 现在帧缓冲的地址应该是一样的! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |