Hi,
In one of my projects, I continue to encounter a problem I cannot seem to solve. I've spotted where the problem comes from, but I can't see what causes it. The culprit is this function:
Code:
function assign(ENTITY* unit,ENTITY* targ,var todo) {
	sys_marker("001");
	VECTOR* to;	
	var temp1;
	var temp2;
	if (unit != NULL && todo >= 0) {
		if (targ != NULL) {
			unit.parent = targ;
			unit.skill12 = 1;
			unit.skill20 = todo;
			unit.skill21 = 1;
		} else {
			unit.parent = NULL;
			unit.skill12 = 1;
			unit.skill20 = todo;
			temp1 = mouse_pos3d.z;
			temp2 = temp1 / -mouse_dir3d.z;
			vec_set(to,mouse_dir3d);
			vec_scale(to,temp2);
			vec_add(to,camera.x);
			
			vec_set(unit.skill15,to);
			unit.skill21 = 1;
		}
	} else {
		if (unit != NULL) {
			unit.parent = NULL;
			unit.skill12 = 0;
			unit.skill20 = 0;
			unit.skill21 = 1;
		}
	}
	sys_marker("002");
}



This is where I call up the function:
Code:
if (key_m) {
	sys_marker("014");
	mouse_map = cursor2;
	sys_marker("017");
	if (isClick) { sys_marker("018"); assign(temp_ent,mouse_ent,1); }
	sys_marker("003");
}



The function runs fine with any combination of parameters, but I get an error ("Crash in main: 018") when I attempt to call 'assign' after the second parameter was NULL once. The function is used to assign tasks to individual entities, and it is absolutely neccesary that this function works without any problems.
Does someone have any idea why this might be happening?
Thanks in advance!
~TehV

EDIT: Changed title. Problem was solved.

Last edited by TehV; 10/11/12 17:20.