Code:
#include <default.c>
#include <ackphysX.h>
#include <mtlFX.c>

ENTITY *pole;
ENTITY *flag_ent;

action flag(){
	flag_ent = me;
//	while(!pole){wait(1);}
	my.material = mtl_twosided_alpha;
	// attach flag to pole
	c_setminmax(pole);
	c_setminmax(my);
	vec_set(my.x,vector(pole.x, pole.y+(my.max_y-my.min_y)/2, pole.z+pole.max_z-(my.max_z-my.min_z)/2));
	// setup flag cloth	
	var cloth_options[40];
	memcpy(cloth_options,CLOTH_DEFAULT,40*sizeof(var));
	vec_set(cloth_options[25],vector(-10,20,0));  // external acceleration
	vec_set(cloth_options[28],vector(5,10,5));  // random wind acceleration
	cloth_options[9] = 4; // Tear Factor
	cloth_options[37] |= NX_CLF_GRAVITY|NX_CLF_BENDING|NX_CLF_COLLISION_TWOWAY|NX_CLF_SELFCOLLISION|NX_CLF_TEARABLE|NX_CLF_BENDING_ORTHO;
	pXent_cloth(my,pole,0,NULL,NULL,cloth_options);
}

action flag_pole(){
	pole = me;
	vec_set(pole.scale_x,vector(0.2,0.2,40));
	vec_set(pole.pan,vector(0,0,0));
	vec_set(pole.blue,COLOR_GREY);
	pXent_settype(pole,PH_STATIC,PH_BOX);
}

void create_flag(){
	ent_create(CUBE_MDL,vector(0,0,0),flag_pole);
	
	ent_create("clothflag.mdl",nullvector,flag);
}

//void destroy_physic(){
//	ent_remove(pole);
//	ent_remove(flag_ent);
//	physX_destroy();
//}
void p_open()
{
	pXent_settype(pole,0,0);
	pXent_settype(flag_ent,0,0);
	pXent_settype(NULL,0,0);
	wait(1);
	ptr_remove(pole);
   ptr_remove(flag_ent);
   wait(1);
	//physX_open();	
	level_load(NULL);
	vec_set(sun_angle.pan,vector(300,60,5000));
	vec_set(camera.x,vector(-1200,100,500));
	vec_set(camera.pan,vector(0,-10,0));
}

function main(){	
	fps_max = 60;
	physX_open();
	level_load("");
	vec_set(sky_color,COLOR_BLUE);
	vec_set(sun_angle.pan,vector(300,60,5000));
	vec_set(camera.x,vector(-1200,100,500));
	vec_set(camera.pan,vector(0,-10,0));
	
		//on_d = destroy_physic;
		on_o = p_open;
		on_c = create_flag;
	
}



Ok I'll stop - This runs and does not crash - however debug panel fnc - ticks up and up and performance chocks , I don't know why.