我有一个C++对象:从视图控制器中调用C++类崩溃的是,我发现了参考我的视图控制器这样
m_applicationEngine = (ApplicationEngine *)[(GLView *)[self.parentViewController view] m_applicationEngine];
在我的位置委托我叫methid在类是这样的:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
CLLocationCoordinate2D coordinate = [newLocation coordinate];
NSLog(@"Location acquired %f, %f", coordinate.latitude, coordinate.longitude);
myLocation = new Location(coordinate.latitude, coordinate.longitude);
m_applicationEngine->GotoLoc(myLocation);
}
它调用GotoLoc功能,但它崩溃第一次函数访问m_applicationEngine实例的公共成员变量。我是积极的成员已经初始化。有人有主意吗?
m_applicationEngine是在GLView:UIView的initWithFrame()中初始化的C++对象。
m_applicationEngine = new ApplicationEngine(m_renderingEngine, self);
这里是GotoLoc()的代码。它第一次引用m_rotation,它是它崩溃的类的成员变量。我可以在代码的其他区域调用GotoLoc(),而不是在上面的Obj-C委托函数中。
void ApplicationEngine::GotoLoc(Location *location) {
vec3 eye = vec3(0, 0, 1);
vec3 end = location->loc;
// Compute the difference between where we're looking at now vs. where we want to point
mat4 transpose;
MatrixTranspose(transpose, m_rotation);
MatrixVec3Multiply(eye, eye, transpose);
//cout << "Inverse. I was here x:" << relativeVec.x << " y:" << relativeVec.y << " z:" << relativeVec.z << endl;
// bring vectors down to the equator to measure x angle
vec3 relativeX = vec3(eye.x, 0, eye.z);
// reference vector is the rotation axis for the sign to be correct
float xAngle = signed_angle(relativeX, vec3(end.x, 0, end.z), vec3(0,-1,0));
mat4 rotationX;
MatrixRotationY(rotationX, -1 * xAngle);
MatrixMultiply(m_rotation, rotationX, m_rotation);
// need to rotate eye vector to line up on y with new target to measure y angle
MatrixTranspose(transpose, rotationX);
MatrixVec3Multiply(eye, eye, transpose);
float yAngle = signed_angle(eye, end, vec3(1,0,0));
cout << "Went to difference of: ANGLE x: " << RADIANS_TO_DEGREES(xAngle) << " y:" << RADIANS_TO_DEGREES(yAngle) << endl;
mat4 rotationY;
MatrixRotationX(rotationY, -1 * yAngle);
MatrixMultiply(m_rotation, m_rotation, rotationY);
}您提供给我们的信息
Location和m_applicationEngine的代码是什么 – Mark 2010-07-12 07:33:45