0t3ch / aforge

Automatically exported from code.google.com/p/aforge
Other
0 stars 0 forks source link

x86 Memory Leak #306

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I am trying to use AForge.NET in my application as a webcam capture source. 
Everything runs great in x64, but x86 has some problems:

When calling this 
int i = tmpdev.VideoCapabilities.Length;
it will lead to an "AccessViolationException - Attempted to read or write 
protected memory. This is often an indication that other memory has been 
corrupted" in my program. There seems to be a memory leak affecting only the 
x86 version of AForge.Net. It is not the device creation but requesting the 
Length of the VideoCapabilities array.

Unable to cast COM object of type ‘System.__ComObject’ to interface 
type’AForge.Video.DirectShow.Internals.IAMVideoControl’. This operation 
failed because the QueryInterface call on the COM component for the interface 
with IID ‘{6A2E0670-28E4-11D0-A18C-00A0C9118956}’failed due to the 
following error: No such interface supported (Exception from HRESULT: 
0×80004002)

Original issue reported on code.google.com by stephans...@gmail.com on 4 Jul 2012 at 10:04

GoogleCodeExporter commented 9 years ago
Which version of the framework is used?

I just checked the 2.2.4 version on x86 with similar configuration you have - 
it works fine.

Original comment by andrew.k...@gmail.com on 4 Jul 2012 at 11:08

GoogleCodeExporter commented 9 years ago
I am using 2.2.4

Original comment by stephans...@gmail.com on 4 Jul 2012 at 11:12

GoogleCodeExporter commented 9 years ago
            _WebcamDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            int num = 0;
            foreach (FilterInfo info in _WebcamDevices)
            {
                SWebcamDevice device = new SWebcamDevice {
                    ID = num,
                    Name = info.Name,
                    MonikerString = info.MonikerString,
                    Capabilities = new List<SCapabilities>()
                };
                num++;
                VideoCaptureDevice tmpdev = new VideoCaptureDevice(info.MonikerString);

                for (int i = 0; i < tmpdev.VideoCapabilities.Length; i++ )
                {
                    SCapabilities item = new SCapabilities
                    {
                        Framerate = tmpdev.VideoCapabilities[i].FrameRate,
                        Height = tmpdev.VideoCapabilities[i].FrameSize.Height,
                        Width = tmpdev.VideoCapabilities[i].FrameSize.Width
                    };
                    device.Capabilities.Add(item);
                }
            }

Commenting out the for loop, would make it run on x86 as well but I need to 
grab the Videocapabilities for all devices.

Original comment by stephans...@gmail.com on 4 Jul 2012 at 11:23

GoogleCodeExporter commented 9 years ago
Can not reproduce. There is no memory leak as you claim. Your camera simply 
does not implement IAMVideoControl interface. But if you have a look at 
framework sources, then you can find that part is protected with try/catch.

Try debugging with framework sources ...

Original comment by andrew.k...@gmail.com on 4 Jul 2012 at 11:30

GoogleCodeExporter commented 9 years ago
I already tried to debug with framework sources, but could not catch that error 
yet. It's really strage as it's running on x64. 

Original comment by stephans...@gmail.com on 4 Jul 2012 at 11:33