getPerspectiveTransform crash on iOS4.3.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

getPerspectiveTransform crash on iOS4.3.

pierre.lamot
Hi folks,

I'm currently developing an application on iphone based on opencv and I'm experiencing some random crash with functions using lapack.
My program use to work fine with previous version of iOS (4.1 and 4.2) but crash with 4.3. The weird things is that it only occurs when the code is executed from a thread. If I run it in the main loop it seems to run fine.

However, if i link the code with opencv_lapack, the program seems to run without issue. So I'm not really sure whether the problems comes from opencv or from the Accelerate framwork, but I tried to write a program using dgelsd_ (which is the only lapack function used in this case, AFAIK), but it didn't reproduce the problem.

Here is a sample code to highlight the problem:

------8<---------------8<---------------8<-----------------
#import <UIKit/UIKit.h>
#include <iostream>
#include <opencv2/imgproc/imgproc.hpp>
#include <pthread.h>

int main(int argc, char *argv[])
{
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        int retVal = UIApplicationMain(argc, argv, @"UIApplication", @"AppDelegate");
        [pool release];
        return retVal;
}

@interface AppDelegate : NSObject <UIApplicationDelegate>
{
        pthread_t mythread;
}
@end

@implementation AppDelegate

static bool m_stop;


void* mytest(void* unused)
{
        cv::Point2f* basePoints2D = new cv::Point2f[4];
        basePoints2D[0] = cv::Point2f(0.0f,0.0f);
        basePoints2D[1] = cv::Point2f(10.0f,0.0f);
        basePoints2D[2] = cv::Point2f(10.0f,10.0f);
        basePoints2D[3] = cv::Point2f(0.0f,10.0f);
       
        cv::Point2f* projPoints2D = new cv::Point2f[4];
        projPoints2D[0] = cv::Point2f(1.0f,5.0f);
        projPoints2D[1] = cv::Point2f(10.0f,5.0f);
        projPoints2D[2] = cv::Point2f(10.0f,10.0f);
        projPoints2D[3] = cv::Point2f(1.0f,10.0f);
       
        //this loop crash
        while (!m_stop)
        {
                cv::Mat m = getPerspectiveTransform(basePoints2D, projPoints2D);
                std::cout << "threadloop " << m.cols << std::endl;
        }
        delete[] basePoints2D;
        delete[] projPoints2D;
        return NULL;
}

       
- (void)applicationDidFinishLaunching:(UIApplication *)application {
#pragma unused(application)
        cv::Point2f* basePoints2D = new cv::Point2f[4];
        basePoints2D[0] = cv::Point2f(0.0f,0.0f);
        basePoints2D[1] = cv::Point2f(10.0f,0.0f);
        basePoints2D[2] = cv::Point2f(10.0f,10.0f);
        basePoints2D[3] = cv::Point2f(0.0f,10.0f);
       
        cv::Point2f* projPoints2D = new cv::Point2f[4];
        projPoints2D[0] = cv::Point2f(1.0f,5.0f);
        projPoints2D[1] = cv::Point2f(10.0f,5.0f);
        projPoints2D[2] = cv::Point2f(10.0f,10.0f);
        projPoints2D[3] = cv::Point2f(1.0f,10.0f);
       
        //this loop runs fine
        for(int i = 0; i < 1000; i++)
        {
                cv::Mat m = getPerspectiveTransform(basePoints2D, projPoints2D);
                std::cout << "mainloop " << i  << " " << m.cols << std::endl;
        }
        delete[] basePoints2D;
        delete[] projPoints2D;

        m_stop = false;
        pthread_create(&mythread, NULL, mytest, NULL);
}
       
- (void)applicationWillTerminate:(UIApplication *)application {
#pragma unused(application)
        m_stop = true;
        pthread_join(mythread, NULL);
}
       
@end
------>8--------------->8--------------->8-----------------




the application logs says:

  ...
  threadloop 3
  threadloop 3
  TestCV(2666,0x1f3000) malloc: *** error for object 0x272dc4: incorrect checksum for freed object - object was probably modified after being freed.



I also have the same kind of issue with the function solvePnP



My version of OpenCV is 2.2.0 (tarball version), I only patched the library to avoid the compilation of highgui (CMakefiles)

OpenCV has been comiled as following:

cmake \
    -D CMAKE_BUILD_TYPE=Debug \
    -D BUILD_NEW_PYTHON_SUPPORT=OFF \
    -D BUILD_SHARED_LIBS=OFF \
    -D BUILD_TESTS=OFF \
    -D BUILD_TESTS=OFF \
    -D OPENCV_BUILD_3RDPARTY_LIBS=OFF \
    -D WITH_1394=OFF \
    -D WITH_CARBON=OFF \
    -D WITH_FFMPEG=OFF \
    -D WITH_JASPER=OFF \
    -D WITH_PVAPI=OFF \
    -D WITH_QUICKTIME=OFF \
    -D WITH_TBB=OFF \
    -D WITH_TIFF=OFF \
    -D WITH_JPEG=OFF \
    -D WITH_CUDA=OFF \
    -D WITH_OPENEXR=OFF \
    -D WITH_PNG=OFF \
    -D CMAKE_OSX_SYSROOT="${SDK_ROOT}" \
    -D CMAKE_OSX_ARCHITECTURES="armv7" \
    -D CMAKE_C_COMPILER="${DEVELOPER_ROOT}/usr/bin/gcc" \
    -D CMAKE_CXX_COMPILER="${DEVELOPER_ROOT}/usr/bin/g++" \
    -D CMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \
    -D ENABLE_SSE=OFF \
    -D ENABLE_SSE2=OFF \
    -D OPENCV_EXTRA_C_FLAGS="-DHAVE_VECLIB" \
    "${OPENCV_ROOT}"

The test case has been compiled with following options:
- architecture: armv7 only
- compiler GCC4.2 (instead of llvm-gcc4.2)
- and linked against: opencv_core, opencv_imgproc, libz(from apple) and Accelerate(apple)

and has been tested on an ipod touch 4g

thanks for your attention,

Pierre


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: getPerspectiveTransform crash on iOS4.3.

Koji Ohno
This post has NOT been accepted by the mailing list yet.
Change -D OPENCV_BUILD_3RDPARTY_LIBS to ON to build 3rd part libs.
Use libopencv_lapack.a instead of Accelerate.framework.

This worked for me.
Loading...