Calling a class function within a struct causes access violation

Hi

I'm trying to call a class function within a struct, which causes a 0xC0000005 Access violation. It works fine when calling the function when it's not within the struct. I'm fairly sure the problem is with the way the struct is being handled, so I think the problem code is in here somewhere. I've included some of the class code to show where exactly the debugger says there's a problem;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Camera_Ray
{
public:
	core::line3d<f32> line;
        core::vector3df intersection;
	core::triangle3df hitTriangle;
	scene::ISceneManager* mgr;
	scene::ISceneNode* selectedSceneNode;
	scene::ICameraSceneNode* camera;
	scene::ISceneCollisionManager* collMan;

	void setup(scene::ISceneManager* mgr, scene::ISceneCollisionManager* cMan, scene::ICameraSceneNode* cam)
	{
		collMan=cMan;
		camera=cam;
	}

	void update(f32 frameDeltaTime, core::vector3df relative_line_end, core::vector3df desired_position)
	{
		line.start = desired_position;
		line.end = desired_position + relative_line_end;
		
		selectedSceneNode = collMan->getSceneNodeAndCollisionPointFromRay(line,intersection,hitTriangle,ID_Collide,0); //<-- debugger points to this line
	}
}
	
struct arm {
	core::vector3df position;
	Camera_Ray ray;
};

arm rightarm, leftarm;

void setup_arm(arm &which_arm)
{
	which_arm.ray.setup(mgr,collMan,camera);
}
	
Camera_Ray temp_ray;
	
setup_arm(rightarm);
	
temp_ray.setup(mgr,collMan,camera);
	
temp_ray.update(frameDeltaTime, core::vector3df(10,0,0), desired_position); // <--- this bit works fine
	
rightarm.ray.update(frameDeltaTime, relativeTarget, desired_position); // <--- this causes a crash 


Any help is much appreciated!
You're trying to read or write to memory that isn't yours. This typically happens when a pointer is pointing at the wrong place, or you overrun an array.
Thanks, I found the problem. I was calling setup_arm before I had set *collMan to point to anything, and temp_ray.setup afterwards. (note to self: actually listen to the debugger next time)
Topic archived. No new replies allowed.