Imagination PowerVR SDK Blog

"EXC_BAD_ACCESS" accessing CPVRTModelPOD.pCamera


#1

Hello everyone,





After starting a project using xCode’s OpenGL app template, I decided to modify it to render a POD file straight to a renderer object from a container class. However, only my glClearColor is showing up. Here are the relevant classes on Pastehub.com:





ES2Renderer.h


ES2Renderer.m


PlayTest.h


PlayTest.mm


Ship.h


Ship.mm


Sprite3D.h


Sprite3D.mm


Model.h


Model.mm


GLProgram.h


GLProgram.m





GameState protocol:





Code:

#import <UIKit/UIKit.h>


@protocol GameState

-(void) updateLoop;

@optional
-(BOOL) handleEvent:(void*)event;

@end



GLCommon.h is included in the example project in this blog post. The needed POD files are in the project at http://sourceforge.net/projects/iphonegamebook/files/iPhoneGameBook_CH5/.MachCUBED2011-02-18 23:22:16

#2

Ok, I decided to change my Model.mm file with the code from the PVR tutorial. Model.h now looks like this:





Model.h


Model.mm





I’m getting an EXC_BAD_ACCESS in the debugger console at the following line in -(void)draw:





Code:

if(model.pCamera[i32CamID].nIdxTarget != -1) // Does the camera have a target?



This is despite the fact that it works just fine in the IntroducingPOD Tutorial example, in the C++ method RenderScene(). In fact, -(void)draw is just an Obj-C implementation of RenderScene(), except that the following timer code is commented out:



Code:

//Calculates the frame number to animate in a time-based manner.
      //Uses the shell function PVRShellGetTime() to get the time in milliseconds.

     int iTime = PVRShell::PVRShellGetTime();
     int iDeltaTime = iTime - m_iTimePrev;
     m_iTimePrev     = iTime;
     m_fFrame += (float)iDeltaTime * g_fDemoFrameRate;
     if (m_fFrame > scene->nNumFrame - 1)
          m_fFrame = 0;



What's going on? Changing model back to a void pointer and typecasting it, the changing everything to pointers in my class only cases an EXC_BAD_ACCESS in PVRTModelPOD. Please help. Moderator, please change this thread's title to ""/EXC_BAD_ACCESS"/ when accessing CPVRTModelPOD.pCamera".