problem with prerender callbacks ....

Hello everyone, it's been a long time I didn't post on script spot !

I have a problem with a preRenderEval callback. I want to modify geometry at each rendered frame with a function I made.
It works fine if I render only one frame, and my function does work.

But when I want to render more than 1 frame, renderer fails at the beginning of the second frame.
I just can't figure out what I am doing wrong ....

Could somebody help me.

try(delete $ref_uv*)catch()
 
 
 
 
callbacks.removeScripts id:#MrGAG
function gag_func = 
(	
	grille_uv = $Plane01
 
	min_point_u = grille_uv.min.y
	min_point_v = grille_uv.min.z
 
	uv_min = sphere radius:2 name:"ref_uv_min"
	uv_min.pos.y = min_point_u 
	uv_min.pos.z = min_point_v
 
	print( "ref_uv_min_u : " + uv_min.pos.y as string)
	print( "grille_uv.min.y: " + grille_uv.min.y as string)
 
	max_point_u = grille_uv.max.y
	max_point_v = grille_uv.max.z
 
 
 
	uv_max = sphere radius:2 name:"ref_uv_max"
	uv_max.pos.y = max_point_u 
	uv_max.pos.z = max_point_v
 
	print( "ref_uv_max_u : " + uv_max.pos.y as string)
	print( "grille_uv.max.y: " + grille_uv.max.y as string)
 
	grille_h = uv_max.pos.z  - uv_min.pos.z 
	grille_w = uv_max.pos.y  - uv_min.pos.y	
 
	sel_set = selectionSets["dechets_reactor"]
 
	for o=1 to sel_set.count do
	(
		id_rand_val = random 1 10
 
		addModifier sel_set[o] (UVWmap())
 
		convertToMesh sel_set[o] 
		-- resolution de l'UV en rapport avec les dimensions du plan de reference
		o_u =  ((sel_set[o] .pos.y - uv_min.pos.y)/grille_w)
		o_v =  ((sel_set[o] .pos.z - uv_min.pos.z)/grille_h)
		for i=1 to (meshop.getNumVerts sel_set[o]) do
		(
			meshop.setMapVert sel_set[o] 1 i [o_u,o_v,0]
			hey = meshop.getMapVert sel_set[o] 1 i --[0,0,0]
			print hey
		)
	)	
)
 
callbacks.addScript #preRenderEval "gag_func()" id:#MrGAG