How to pass buffer of video frame data into ofImage?

I want to pass the unsigned char* array ‘buffer’ (frame buffer) into an image,so that I can have an image that contains frames of the video grabber,

my code:

when I run it,it can build succeeded but in ‘ofImage.cpp’there is an error"Thread 1:EXC_BAD_ACCESS’ imediately as below: