Bonjour,

Voici un bout de code, utlisant en interne la STL, qui demande un check avant assignation
d'un pointeur et sachant qu'il y a dereferencement il faut tester que le pointeur n'est pas null.


Mais est ce que la mani�re ci-dessous (//2. dans la fonction UpdateTracerset()) est la bonne m�thode ?


/*functions et header*/
Code : S�lectionner tout - Visualiser dans une fen�tre � part
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
 
	/*rawcorner.h*/
 
	// an_rawcorner_alloc()
	inline unsigned char *an_rawcorner_alloc()
	{
		return (unsigned char *)calloc(sizeof(char),RAWCORNER_TOTAL_SIZE);
	}
 
 
 
	/*cornerlist.h*/
 
	// -------------------------------
	//  Title   : get_first
	//  Descript: gives a pointer to the first corner data of the list 
	//            and initializes the internal pointer to the first corner
	//	IN		: nothing
	//	OUT		: nothing
	//	Return  : pointer to the pointer to the data of the first corner
	//			  NULL if the list is empty
	// ------------------------------------------
	virtual unsigned char **get_first()=0;
 
	// ---------------------
	//  Title   : get_next
	//  Descript: gives a pointer to the next corner data of the list 
	//	IN		: nothing
	//	OUT		: nothing
	//	Return  : pointer to the pointer to the data of the next corner
	//			  NULL if at the end of the list, or list empty or internal pointer not initialized
	// -----------------------------------------------
	virtual unsigned char **get_next()=0;
 
	Ccornerlist_Int (){..};
/*// Wrapper interne dll (tracer_tool.cpp) */
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
	/*tracer.cpp*/
 
	// Wrapper to internal dll 
 
	DLL(long) update_tracer_set(void** tracerInstance, CCornerList_Int* newCornerList,unsigned char * currentCorner)
{
 
	int returnValue = 0;
 
	if (*tracerInstance!=NULL){
		static_cast<TracerTool*>(*tracerInstance)->updateTracerSet(newCornerList, currentCorner);
		returnValue = 0;
	}
	else {
 
		returnValue = -2;
	}
 
	return returnValue; 
 
};

/* call */
Code : S�lectionner tout - Visualiser dans une fen�tre � part
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
 
	/*call.cpp*/
 
	//function
	// write fixed data in a corner struct in function of label_id
	void fill_corner(unsigned char *rawCorner,int labelID, int x0_bbox, int y0_bbox, int x1_bbox, int y1_bbox, int trackingID)
	{
		vgt_an_rawcorner_set_long(rawCorner,LABEL_ID_L,labelID);
 
		an_rawcorner_set_long(rawCorner,BBOX_X0_L,x0_bbox); 
		an_rawcorner_set_long(rawCorner,BBOX_Y0_L,y0_bbox); 
		an_rawcorner_set_long(rawCorner,BBOX_X1_L,x1_bbox);
		an_rawcorner_set_long(rawCorner,BBOX_Y1_L,y1_bbox);
 
		an_rawcorner_set_long(rawCorner,TRACKING_ID_L,trackingID);// identifier (-1=unknown)
	}
 
	//extract cornerlist
	Ccornerlist_Int* cornerlistExtracted						= NULL;
	cornerlistModule.create_obj_cornerlist(&cornerlistExtracted);
 
	unsigned char* corner2			                    		= an_rawcorner_alloc();
 
	fill_corner(corner2, 1,320,19,350,49,7);
	//add to cornerlist
	cornerlistExtracted->add(corner2);
 
	fill_corner(corner2, 2,160,8,175,24,8);
	//add to cornerlist
	cornerlistExtracted->add(corner2);
 
 
	corner2 = *(cornerlistExtracted->get_first());  //est ce la bonne méthode ?
 
	pCtracer->update_tracer_set(&tracerInstance, cornerlistExtracted,corner2);
 
	...
Enfin la dll interne ou se trouve le bug
/* DLL interne */
Code : S�lectionner tout - Visualiser dans une fen�tre � part
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 
	/*tracer_tool.cpp*/
 
void Tracertool::updateTracerSet(CCornerList_Int* newCornerList, unsigned char * currentCorner){
 
	// reset the update status of all the (simple) corners
	map<int, SimpleCorner* >::iterator itSimpleCornerList;
	for (itSimpleCornerList = SimpleCornerList.begin(); itSimpleCornerList!=SimpleCornerList.end(); itSimpleCornerList++){		
		(*itSimpleCornerList).second->isUpdated = false;	
		(*itSimpleCornerList).second->timeElapsedSinceLastUpdate++;
 
	}
 
	// for all the current corners
	//unsigned char *currentCorner = newCornerList->get_first();
	//unsigned char **currentCorner = vgt_an_rawcorner_alloc();
	//unsigned char *currentCorner = vgt_an_rawcorner_alloc();
 
//	strcpy((char*)currentCorner,(const char*) newCornerList->get_first()) ;
	printf("a. value of newCornerList->get_first() =%p\n",newCornerList->get_first());
    currentCorner=*(newCornerList->get_first());
	printf("b. value of currentCorner after assign =%p\n",currentCorner);
 
	while (currentCorner !=NULL){
 		//int trackingID = currentCorner->tracking_id;
		long trackingID =0;
 		vgt_an_RawCorner_get_long(currentCorner,TRACKING_ID_L,&trackingID);
 
 		// search corresponding simple corner
 		map<int, SimpleCorner* >::iterator itcornerTracer= this->SimpleCornerList.find(trackingID);
		// if it exists
		if (itcornerTracer!=SimpleCornerList.end()){		
			(*itcornerTracer).second->isUpdated = true;
			(*itcornerTracer).second->timeElapsedSinceLastUpdate = 0;
			// if the corner exist for a number of frame >= MAX_TRACER_SIZE 
			if ((*itcornerTracer).second->tracer.size() >= (*itcornerTracer).second->tracer_MAX_SIZE ){ 
 
				//erease first element of real tracer
				delete (*(*itcornerTracer).second->tracer.begin());
				(*itcornerTracer).second->tracer.erase( (*itcornerTracer).second->tracer.begin() );
 
			}
 
			//addPointTotracer(currentCorner,(*itcornerTracer).second );
			addPointTotracer(currentCorner,(*itcornerTracer).second );
			//addPointToSmoothtracer(currentCorner,(*itcornerTracer).second, 3);			
			addPointToSmoothtracer(currentCorner,(*itcornerTracer).second, 3);			
		}
		// else create new simple corner
		else{
			SimpleCorner* newcorner = new SimpleCorner();
			newcorner->isUpdated=true;
			newcorner->timeElapsedSinceLastUpdate=0;
			// add the corner to the intern  list
			this->SimpleCornerList.insert(pair<int, SimpleCorner*>(trackingID, newcorner));
		}
 
		//1.
		//currentCorner=*(newCornerList->get_next()); !! ACCESS VIOLATION QUAND FONCTION RETOURNE NULL
 
		//2.
		//est ce une solution acceptable pour tester la condition NULL ? 
		unsigned char ** temp=newCornerList->get_next();
		if(temp!=0)
			currentCorner=temp;
		else
			currentCorner = NULL;
 
		//3. Ou l'utilisation de strcpy ?  
		//strcpy((char*)currentCorner,(const char*)newCornerList->get_next()) ;
 
	}
 
 
};
Dans mon call la ligne:
corner2 = *(cornerlistExtracted->get_first());
ne genere pas d'erreur par contre le ->get_next() bien .

Le bug est dans la fonction updateTracerSet et j'hesite entre diff�rentes solutions possibles , quelle est une autre meilleure solution?

Merci