0

这不适用于新的 Swift 项目。给我一个EXC_BAD_ACCESS code=1 errorAppDelegate。

UIViewController.swift

import UIKit


class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        view.layoutIfNeeded()
        Test(view: view)

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

测试.swift

import UIKit
import GLKit
import OpenGLES

final class Test: NSObject {
    init(view: UIView) {
        super.init()
        let context = EAGLContext(API: EAGLRenderingAPI.OpenGLES2)
        EAGLContext.setCurrentContext(context)
        let glView = GLKView(frame: view.bounds)
        glView.context = context
        glView.delegate = self
        view.addSubview(glView)
    }
}

extension Test: GLKViewDelegate {
    func glkView(view: GLKView, drawInRect rect: CGRect) {
        glClearColor(1.0, 0.0, 0.0, 1.0)
        glClear(GLbitfield(GL_COLOR_BUFFER_BIT))
    }
}

将所有代码放在里面ViewController确实有效。

我正在构建一个更大的应用程序,它具有与此类似的设置。但是收获很多EXC_BREAKPOINT code=1 errors。如果我在模拟器中运行,此错误会有所不同。

4

0 回答 0