0

I am using the Java fftw3 wrapper taken from this question. (Code here)

I just wanted to apply a 2nd type DCT transform to an array of double elements, but I keep getting this error if i try to call the fftw_execute method:

java(787,0x10b243000) malloc: *** error for object 0x7fba642c5408: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug

Why?

Here's my code:

package com.project.fftw3;

import java.io.File;
import java.io.IOException;
import java.nio.DoubleBuffer;

import fftw3.FFTW3Library;
import fftw3.FFTW3Library.fftw_plan;

public class MainClass {
    static FFTW3Library fftw = FFTW3Library.INSTANCE;

    public static void main(String[] args) {
        int i,j,w,h;
        File in = new File("Images/Baboon.bmp");
        //File out = new File("Baboon-" + System.currentTimeMillis() + ".txt");
        try {
            ImageMatrix im = new ImageMatrix(in);
            w=im.getImageWidth();
            h=im.getImageHeight();
            double [] row = im.getRow(0);
            double [] oarr = new double[w];
            DoubleBuffer din = DoubleBuffer.wrap(row);
            DoubleBuffer dout = DoubleBuffer.wrap(oarr);
            fftw_plan p = fftw.fftw_plan_dft_1d(din.array().length,din,dout,5,FFTW3Library.FFTW_ESTIMATE); //5 is REDFT10
            fftw.fftw_execute(p);
            fftw.fftw_destroy_plan(p);
        } catch (IOException e) {
        }
    }
}
Community
  • 1
  • 1
Vektor88
  • 4,841
  • 11
  • 59
  • 111

1 Answers1

0

It looks like you have the wrong dimension here:

        double [] oarr = new double[h];

Change this to:

        double [] oarr = new double[w];

This is consistent with the error you are seeing, assuming w > h.

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • This is surely an error, but my test image is 512x512 and I still have the problem – Vektor88 May 31 '14 at 10:30
  • 1
    In that case all I can suggest is to check the docs in regard to required buffer sizes, as it sounds like you are writing beyond the end of an allocated buffer and corrupting the heap. – Paul R May 31 '14 at 10:34
  • I've seen that buffers are defined this way `in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);` and `fftw_complex` is defined as `typedef double fftw_complex[2];` So i tried `oarr=new double[w*2]`. I get no error but the resulting array contains all zeroes. – Vektor88 May 31 '14 at 13:27
  • 1
    I've switched to C++ , but your guess was correct. Once I made it in C++, I understood that the buffer were wrongly sized and badly populated. – Vektor88 Jun 03 '14 at 14:55