作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
一段时间以来,我一直在努力解决这个问题,但无法弄清楚为什么会这样。它似乎只发生在“存档”应用程序并在设备上运行时,而不是调试应用程序时。
我有两个类:
@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
当包含它的对象不改变时,这个成员变量的地址怎么会改变?
最佳答案
为什么不使用指针呢?您保证地址将是相同的。将 EAGLView 修改成这样
@interface EAGLView : UIView
{
@public
GLuint *framebuffer;
}
打印出 framebuffer
的地址:
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 );
}
现在帧缓冲区的地址应该相同!
关于c++ - 当包含它的对象不改变时,这个成员变量的地址如何在 objective-c 中改变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19710756/
我是一名优秀的程序员,十分优秀!