From: Peter N. <jpn...@ho...> - 2007-11-13 15:35:22
|
Hello. I think i have found a bug in the sicklms200.cc file from the CVS HEAD ve= rsion. I am using Debian Stable 4.0 with kernel 2.6.18-5-686. The CVS id tag is CVS: $Id: sicklms200.cc,v 1.65 2007/11/01 22:16:19 gerk= ey Exp $ When i start the player server with a laser-only.cfg file this is what ha= ppens. =20 "player -d 9 laser.cfg" -------------------------------------------------------------------------= ----- Laser initialising (/dev/ttyUSB0) connecting at 9600 sending configuration mode request to laser waiting for acknowledge laser operating at 9600; changing to 38400 SICK laser type [LMS200;301063;V02.32 ] at [/dev/ttyUSB0:38400] laser ready listening on 6665 Listening on ports: 6665 receiving data Segmentation fault -------------------------------------------------------------------------= ----- I have been able to track down the line were the error occurs by using s= ome quick "printf debugging". The line is 706 in sicklms200.cc were it says: =20 =20 703 for (int i =3D 0; i < this->scan_max_segment - this->scan_min_seg= ment + 1; i++) 704 { 705 data.intensity[i] =3D ((mm_ranges[i] >> 13) & 0x0007); 706 data.ranges[i] =3D (mm_ranges[i] & 0x1FFF) * this->range_res= / 1e3; 707 } This is were the laserdata is stored in "data.ranges[i]". I think that da= ta.ranges never gets any memory allocated the first time the program runs= . (data.ranges seem to be a pointer to float according to libplayercore/int= erfaces/006_laser.def). A quick fix was to add "data.ranges_count =3D 0 " after line 670. By doin= g this I can force memory to be allocated by the IF on lines 695-702 This would "solve" that problem but after the loop on line 703 is complet= e a new segmentation fault error occurs on line 731-733 in th Publish cal= l. I dont know what is causing this. Could it perhaps be the use of sizeof(d= ata). Does that work when data has members with dynamic memory allocation= ? (Well I don't know, its just a thought) =20 =20 668 if (first) 669 { 670 PLAYER_MSG0(2, "receiving data"); data.ranges_count =3D 0; 671 first =3D false; 672 } 692 double old_count =3D data.ranges_count; 693 data.ranges_count =3D data.intensity_count =3D 694 this->scan_max_segment - this->scan_min_segment + 1; 695 if (old_count < data.ranges_count) 696 { 697 delete [] data.ranges; 698 delete [] data.intensity; 699 data.ranges =3D new float[data.ranges_count]; 700 data.intensity =3D new uint8_t[data.intensity_count]; 701 702 } 730 // Make data available 731 this->Publish(this->device_addr, =20 732 PLAYER_MSGTYPE_DATA, PLAYER_LASER_DATA_SCAN, 733 (void*)&data, sizeof(data), &time); 734 delete [] data.ranges; 735 delete [] data.intensity; I hope this will be helpful in the hunt for bugs. /Peter Nu =E4r det K=E4rleksvecka p=E5 Spray Date. Vinn en dr=F6mdejt fr=E5n K=E4= rleksfonden. http://www.spraydate.se |