Memory Exception while saving an image
-
Hello I am working in C# and developing a desktop application. The main tasks of my application are Live Video Capturing, recording, transmission over LAN and motion detection. All are doing fine. But sometimes while grabbing a frame; it throws memory exception i-e "Attempted to read or write protected memory. This is often an indication that other memory is corrupt" at line b.Save("C:\\abc.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);// b is a bitmap object ///// other code b.dispose(); and after that it throws exception i-e "A generic error occurred in GDI+". As I m continuously grabbing frames in a loop. So once it throws an exception, it stops working. I m searching over it but still didn't get any solution. plz help me out thx
Shanzay
-
Hello I am working in C# and developing a desktop application. The main tasks of my application are Live Video Capturing, recording, transmission over LAN and motion detection. All are doing fine. But sometimes while grabbing a frame; it throws memory exception i-e "Attempted to read or write protected memory. This is often an indication that other memory is corrupt" at line b.Save("C:\\abc.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);// b is a bitmap object ///// other code b.dispose(); and after that it throws exception i-e "A generic error occurred in GDI+". As I m continuously grabbing frames in a loop. So once it throws an exception, it stops working. I m searching over it but still didn't get any solution. plz help me out thx
Shanzay
Does your code interact with other non-managed code? I've seen this when using a C++ DLL from C#. When the error occurs, what field values does the debugger show in the bitmap object? If they're all the same weird byte value, it may mean that object was already Disposed by another part of the code. If this is happening, you need to trace backwards to locate where it occurs.