MemPartAlloc Error When Trying to Access the NIVision Library

So we’ve been trying to use the NIVision library to process images, but we’ve been hitting this exception while running our camera code. This is the exception:

Exception while getting image
[cRIO] edu.wpi.first.wpilibj.image.NIVisionException
[cRIO] 0xeccc20 (camera task executor): memPartAlloc: block too big 1259784 bytes (0x8 aligned) in partition 0x34f600

Can anyone shed some light on this?

We do use to clear the memory on the images, so if anyone has any ideas on what the problem may be please leave your thoughts below.


I am currently experiencing the same issues with the NIvision library. It’d be fantastic if someone had any advice. If not, I’m planning on finding out exactly where this error occurs in my code on friday. If I learn anything useful, I’ll post my findings.

Use the Charts tab on the Driver Station to see how much total memory you have free and the size of the largest block.

I found a memory leak in NIVision.particleFilter(). I believe WPI is working on it…

If you feel daring, you could modify WPILibJ’s NIVision class (sunspotfrcsdk/lib/WPILibJ/src/edu/wpi/first/wpilibj/image/ with this UNTESTED FIX:

    public static int **particleFilter**(Pointer dest, Pointer source, CriteriaCollection collection) throws NIVisionException {
        Pointer particleFilterOptions = new Pointer(16);
        particleFilterOptions.setInt(0, 0);
        particleFilterOptions.setInt(4, 0);
        particleFilterOptions.setInt(8, 0);
        particleFilterOptions.setInt(12, 1);
        IntByReference i = new IntByReference(0);
        **Pointer criteriaArray = collection.getCriteriaArray();**
        assertCleanStatus(imaqParticleFilter4Fn.call7(dest.address().toUWord().toPrimitive(),   // dest image
                                                    source.address().toUWord().toPrimitive(),   // source image
                                                    **criteriaArray.address().toUWord().toPrimitive()**,  // array of criteria
                                                    collection.getNumberOfCriteria(),           // number of criteria in the array
                                                    particleFilterOptions.address().toUWord().toPrimitive(),  // particle filter options
                                                    0,                                          // Region of interest
                                                    i.getPointer().address().toUWord().toPrimitive()));  // returned number of particles
        int numberOfParticles = i.getValue();;
        return numberOfParticles;

You have to make sure to release any images that you create, since they are being ported from C they do not get automatically garbage collected. Use the .free() method on any images.

I got the same issue this year-anyone found a good solution?