I got an Out of memory issue with my code when run program to record screen after a long time.
Source code below...
System::Windows::Media::Imaging::BitmapSource^ Previewer::VideoFrameToBitmapSource(const NuvixaLive::videoFrame* frame)
{
int width = frame->width();
int height = frame->height();
int pixels = width*height;
if( _rgbaFrame == NULL)
{
_rgbaFrame = new videoFrame(width,height,videoFrame::rgba);
}
if(_rgbaFrame->height() != frame->height() ||
_rgbaFrame->width() != frame->width() )
{
SAFE_DELETE(_rgbaFrame);
_rgbaFrame = new videoFrame(width,height,videoFrame::rgba);
}
frame->RGBToRGBA(_rgbaFrame);
_rgbaFrame->FlipV();
BitmapSource^ out = BitmapSource::Create(width, height, 96.0, 96.0,
PixelFormats::Bgra32, nullptr, System::IntPtr(_rgbaFrame->payload()), _rgbaFrame->len() , width*4);
out->Freeze();
return out;
}
and here is stack trace.
System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
at System.Windows.Media.Imaging.CachedBitmap.InitFromMemoryPtr(Int32 pixelWidth, Int32 pixelHeight, Double dpiX, Double dpiY, PixelFormat pixelFormat, BitmapPalette palette, IntPtr buffer, Int32 bufferSize, Int32 stride)
at NuvixaLive.Previewer.VideoFrameToBitmapSource(videoFrame* frame)
at NuvixaLive.Previewer.RaiseNewImage(videoFrame* A_0)
at NuvixaLive.Previewer_imp.renderVideoThread(Previewer_imp* )
at NuvixaLive.Previewer_imp.renderVideoThreadProxy(Void* p)
Would you please take a look and give me any help ?