bug with ofSerial?

I have ofSerial running ok in my project, but when you close the app (with escape) the program crashes with a windows ‘im sorry your program crashed box’. I’ve commented out all my code, slowly turning stuff back on in code until I found it was the serial.

Also, I tried running serialExample (precompiled sample with 0.03) and it crashes before starting up:

Any ideas? Thanks

hi

there are two things:

a) crashing at the end

b) the demo app (0.03 -> vs -> serial -> release) crashes when you try it -

about (b) please just recompile it, I guess there was something that got missed. If I rebuild it it’s fine. it’s likely a build that we missed, nothing to worry about.

about (a), ok , I think it’s the same as the quicktime crashing at the end, which is that I might be doing something aggressive at the end in terms of memory deallocation that it’s unhappy about. soon we will look at ending procedures. Seems to be only happening with VS builds for now, so haven’t noticed them on other compilers. if you feel like poking around, you can try commenting out:

– ofSerial::~ofSerial()
or
– ofSerial::close()

and see if that helps - you might narrow down a specific call that is crashing at the end.

thanks!
zach

in answer to b) this crashes it

ofSerial::~ofSerial()

  
  
for (int i = 0; i < MAX_SERIAL_PORTS; i++) {  
   delete [] portNamesShort[i];  
   delete [] portNamesShort[i];  
}  
delete [] portNamesShort;  
delete [] portNamesShort;  
  

changing it to this it no longer crashes (im not sure if you were supposed to have things in there twice)

  
  
for (int i = 0; i < MAX_SERIAL_PORTS; i++) {  
   delete [] portNamesShort[i];  
}  
delete [] portNamesShort;  
  

Thanks

ah - that’s a bug, should be deleting both:

portNamesFriendly
portNamesShort

and instead it deletes “portNamesShort” twice.
thanks much for catching it !

we are going to try installing bugzilla today, so we should have a system soon for identifying, and cleaning up the bugs we find.

many thanks!!
zach

You beat me to it, I was going to say, here is the full function with the bug fixed for anyone who wants it:

  
  
ofSerial::~ofSerial(){  
	  
	close();  
  
	//---------------------------------------------  
	#ifdef TARGET_WIN32  
	//---------------------------------------------  
		nPorts 				= 0;  
		bPortsEnumerated 	= false;  
	  
		for (int i = 0; i < MAX_SERIAL_PORTS; i++) {  
			delete [] portNamesShort[i];  
			delete [] portNamesFriendly[i];  
		}  
		delete [] portNamesShort;  
		delete [] portNamesFriendly;  
  
	//---------------------------------------------  
	#endif  
	//---------------------------------------------  
	  
	bVerbose = false;  
	bInited = false;  
	  
}  
  

I have been noticing more problems with ofSerial, I dont know if they are related.

Even though the comport (COM4) is not used by another program, when I try to open in ofw it says not available. When I try it in comDebug (as mentioned earlier in this post) it works, then I go back to OFW and port4 works.

Very off

Also, serialPort.enumerateDevices() crashes my application. I can’t run serialExample unless this line is commented out.

Any ideas?

Thanks

hi chris,

what OS / compiler are you using?

can you try commenting out parts of enumerateDevices(), to see why it crashes? can you try running it in debug and release?

can you download the dev-c++ version and see if there are any differences?

it doesn’t crash for me with 1 or 2 arduinos plugged in, so hard to say, but I have to admit it’s not a well tested part of the core so feedback is really appreciated.

I’d be interested to know if you get to these lines before the crash:

  
  
// Search device set  
 	hDevInfo = SetupDiGetClassDevs((struct _GUID *)&GUID_SERENUM_BUS_ENUMERATOR,0,0,DIGCF_PRESENT);  
   

  
  
SetupDiEnumDeviceInfo(.....)  
   

  
  
SetupDiGetDeviceRegistryProperty(.....)  
   

you can start just putting printfs everywhere
printf(“a \n”);

printf(“b \n”);

to see where you get to -

thanks
zach

about this:

Even though the comport (COM4) is not used by another program, when I try to open in ofw it says not available. When I try it in comDebug (as mentioned earlier in this post) it works, then I go back to OFW and port4 works.

I really don’t know - if we can get enumerate devices to work we can get a better sense of what the code sees as available devices.

it works for me so it’s super hard to debug on my end, but just keep trying different things and we’ll get it.

take care,
zach

Im using XP with VS Express 2005.

I found the problem, but dont know why.

Within enumerateWin32Ports() this crashes it:
end = strstr(begin, “)”);

  
  
printf("a \n");  
char *	begin 	= NULL;  
printf("b \n");  
char *	end 	= NULL;  
printf("c \n");  
begin 			= strstr((char *)dataBuf, "COM");  
printf("d \n");  
end 			= strstr(begin, ")");  
printf("e \n");   
  

It gets as far as printing D.

can you check if begin == null

ie,

if (begin == NULL) printf (“begin is null and dataBuf = %s\n”, dataBuf);
right before
printf(“d \n”);

end will fail if this fails:
strstr((char *)dataBuf, “COM”);
but I can’t see why this would fail…

thanks!
zach

I just checked the devc++ code and they look the same.

Your if statement outputs
dataBuf = T

weird, I think you have a port which is not COM1, COM2 - and that’s why it’s crashing.

this code will skip the offending port (or ports) and should output ports that it really can digest. (like COM1, COM2, etc)

another test:

  
  
	char *	begin 	= NULL;  
	char *	end 	= NULL;  
	begin 			= strstr((char *)dataBuf, "COM");  
	if (begin != NULL){  
		end 			= strstr(begin, ")");  
		  
		if (begin){  
		if (end){  
	       	*end = 0;	// get rid of the )...  
	      	strcpy(portNamesShort[nPorts], begin);  
		}          
		}  
		  
		if (nPorts++ > MAX_SERIAL_PORTS) break;  
	}  
}  
i++;  
  

do you have anything besides a normal serial port or arduino, like a usb->serial adapter?

thanks!
zach

Yeah I’m using a usb serial device, i either get COM15, COM4 or COM9. My laptop doesn’t even list com1/com2.

The changes you made stop it crashing now, although it lists no devices.

Been coding ofw all day, off to sleep now to pick this up again tomorrow. Its not urgent for my current situation, but would be good to fix if there is a bug.

Thanks

strange, because this system should work w/ com whatever, like COM20, COM4, etc. can you let me know the model # of the product, I will investigate. the funny thing is that this code, I think, comes from a usb->serial adapater company :slight_smile:

can you try this:

  
  
printf("the computer thinks I am called %s \n", (char *)dataBuf);  
begin 			= strstr((char *)dataBuf, "COM");  
  

the more we can learn about this the better for everyone. today I’ll get back w/ my arduino - . currently, it looks like it’s locking on a weird name or something like that. there are some old school text parsing things there that don’t look so safe, so we will replace them, but I’m very curious to understand the crash.

tx !
zach

Its just called Prolific USB Serial Converter
http://www.usbgear.com/ALL-usb-serial-c-…-erter.html

Here is the test output

ok weird, I think we are not getting good values for this:
SPDRP_FRIENDLYNAME

from the device, and that is causing the crash…

today I am going to read about “SetupDiGetDeviceRegistryProperty” and SPDRP_FRIENDLYNAME and I’ll send you some other code to try. I’ve seen serial port enumeration 7 different ways !! : http://www.naughter.com/enumser.html

it’s a cheap enough device, I’ll pick one up :slight_smile:

thanks !
zach