Hi guys - having some trouble with the below code… OSX activity monitor just shows the programme growing and growing whenever menuState==2 is hit. Presumably there’s something wrong with the way I’m deallocating camPixels? Any ideas?
it’s not a memcpy() problem, but a new/delete problem.
every time you say “new”, there should be a “delete”. if you’re working with an array, then “type* x = new type[];” should be followed by “delete [] x;”
in general you shouldn’t be using new and delete at all. in this case you can use ofPixels, which handles allocation for you.
instead of being an unsigned char*, make camPixels an ofPixels. then instead of memcpy you can just say camPixels = vidGrabber
if you need an unsigned char* for your synthDrawCamRecord, then you can get it with camPixels.getPixels().
ah yes cool - thanks! while i’ve got your ‘ear’, a somewhat related issue…
all this is headed towards an app that grabs frames from a camera while displaying simple animations to the screen - all happening currently in: masterAnalysis.synthDrawCamRecord(camPixels);
it’s a bit like a structured light application - doing some “shape from shadow” and “shape from shading” using a set of test patterns on the screen, where we need to know the exact thing that’s on the screen when an image from the camera comes in. so it’s a sync issue between the camera and the on-screen writing.
when i pass ofPixels the frame saving operations in masterAnalysis.synthDrawCamRecord() block the drawing operation, compared to the unsigned char * method (which I couldn’t get to work properly for other reasons - mem leaks, etc.).
I suppose the question is leading to: Is the best way to record a sync’d frame from a camera while animating to the screen to use threading? That is, start a frame thread and then just ‘tag’ the saved images based on what’s on the screen when the image is taken?
the unsigned char* method and the = operator in ofPixels are doing the same, there shouldn’t be any difference. that said, yes if your application main thread is very time consuming then probably you’ll have better results using a thread to save the images