1

自動参照カウントとゾンビを有効にしています...

私はコード内のさまざまなポイントへのEXCBADACCESSを取得し続けていますが、ほとんどの場合、ゾンビからの情報はありません。

目的は、画像から読み込まれたテクスチャを含む長方形を画面に描画することです。それは実際に機能します!しかし、多くの場合、それは破損しており(画像とベクトル)、その後、excbadaccess警告が表示されることがよくあります。

私はこの種の構造を持っています...

アプリデリゲートクラス宣言:

GWBackgroundScene* background;
EAGLContext *context;
GLKView *view;
GLKViewController *controller;
UIWindow *window;

次に、ウィンドウがプロパティになり、合成されます。

オプションで起動を終了しました:

context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
[EAGLContext setCurrentContext:context];

view = [[GLKView alloc] initWithFrame:[[UIScreen mainScreen] bounds] context:context];
view.delegate = self;

controller = [[GLKViewController alloc] init];
[controller shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
controller.delegate = self;
controller.view = view;

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = controller;
[self.window makeKeyAndVisible];

background = [[GWBackgroundScene alloc] initWithImage:[UIImage imageNamed:@"DSC_0059.jpg"]];

AppDelegateはOpenGLデリゲートとして機能し、OpenGLはクラス内の「render」という関数を呼び出します。この関数は[backgroundrender]を呼び出します。

私のGWBackgroundSceneクラス:

@interface GWBackgroundScene : NSObject
{
    GLKTextureInfo *texture;
    NSMutableData* vertexData;
    NSMutableData* textureCoordinateData;
}  
@property(readonly) GLKVector2 *vertices;
@property(readonly) GLKVector2 *textureCoordinates;
-(void) render;
-(id) initWithImage: (UIImage*)image;

初期化:

self = [super init];

if(self != nil)
{
  texture = [GLKTextureLoader textureWithCGImage:image.CGImage options:[NSDictionary  dictionaryWithObject:[NSNumber   numberWithBool:YES]                                                                                        forKey:GLKTextureLoaderOriginBottomLeft]  error:&error];

    vertexData = [NSMutableData dataWithLength:4];
    textureCoordinateData = [NSMutableData dataWithLength:4];

    self.vertices[0] = GLKVector2Make(-2.0,3.0);     
    ...

    self.textureCoordinates[0] = GLKVector2Make(0,0);
    ...
}

return self;

ベクトルとテクスチャの情報を処理するためのこれらの2つの機能があります

- (GLKVector2 *)vertices {
  return [vertexData mutableBytes];
}
- (GLKVector2 *)textureCoordinates {
return [textureCoordinateData mutableBytes];
}

次に、レンダリング関数(OpenGLによってそのデリゲート(アプリデリゲート)を介して呼び出されます)は以下を使用します。

  1. テクスチャ:

    GLKBaseEffect *effect = [[GLKBaseEffect alloc] init];
    effect.texture2d0.envMode = GLKTextureEnvModeReplace;
    effect.texture2d0.target = GLKTextureTarget2D;
    effect.texture2d0.name = texture.name; 
    
  2. self.vertices:

    glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, self.vertices);
    
  3. self.textureCordinates

    glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 0, self.textureCoordinates);
    

私がしていることに関する明らかなメモリの問題は何ですか?

どうもありがとう

4

1 に答える 1

1

サイズが4バイトのNSMutableDataオブジェクトを作成しましたが、データ型GLKVector2が1バイトを超えています。そこにいくつかのオブジェクトを格納することを期待している場合は、

vertexData = [NSMutableData dataWithLength:4 * sizeof(GLKVector2)];

同様に、textureCoordinateDataについても同様です。

于 2011-11-27T20:48:29.917 に答える