V-REP crash when loading plugin with OpenCV

Report crashes, strange behaviour, or apparent bugs
marcofe
Posts: 16
Joined: 27 Apr 2015, 14:25

V-REP crash when loading plugin with OpenCV

Post by marcofe »

Hi all,
I wrote a c++ plugin, named DPD, that uses OpenCV libraries inside (highgui, imgproc, gpu, core ... ). However, V.REP cannot load it properly, it falls in segmentation fault when trying to load the plugin:

Code: Select all

Using the default Lua library.
Loaded the video compression library.
Add-on script 'vrepAddOnScript-addOnScriptDemo.lua' was loaded.
Simulator launched.
Plugin 'MeshCalc': loading...
Plugin 'MeshCalc': load succeeded.
Plugin 'BubbleRob': loading...
Plugin 'BubbleRob': load succeeded.
Plugin 'Collada': loading...
Plugin 'Collada': load succeeded.
Plugin 'ConvexDecompose': loading...
Plugin 'ConvexDecompose': load failed (could not load). The plugin probably couldn't load dependency libraries. Try 'ldd pluginName.so' for more infos, or simply rebuild the plugin.
Plugin 'CustomUI': loading...
Plugin 'CustomUI': load succeeded.
Plugin 'DPD': loading...
Segmentation fault (core dumped)
This is my Makefile:

Code: Select all

CFLAGS = -I../include -I/usr/local/include -fPIC -static `pkg-config --cflags opencv`
LIBS = `pkg-config --libs opencv`

OPENCVLIBS = /usr/lib

OS = $(shell uname -s)
ifeq ($(OS), Linux)
	CFLAGS += -D__linux
	EXT = so
else
	CFLAGS += -D__APPLE__
	EXT = dylib
endif

TARGET = lib/libv_repExtDPD.$(EXT)

all: 
	@rm -f lib/*.$(EXT)
	@rm -f ../../libv_repExtDPD.$(EXT)
	@rm -f *.o 
	g++ $(CFLAGS) -c v_repExtDPD.cpp -o v_repExtDPD.o
	g++ $(CFLAGS) -c ../common/scriptFunctionData.cpp -o scriptFunctionData.o
	g++ $(CFLAGS) -c ../common/scriptFunctionDataItem.cpp -o scriptFunctionDataItem.o
	g++ $(CFLAGS) -c ../common/v_repLib.cpp -o v_repLib.o
	@mkdir -p lib
	g++ scriptFunctionData.o scriptFunctionDataItem.o v_repExtDPD.o v_repLib.o -o $(TARGET) $(LIBS) -shared -ldl -lpthread 
	@tput bold	
	@echo 'Copying $(TARGET) in V-REP folder ...'
	@tput sgr0
	@cp $(TARGET) ../../
Typing

Code: Select all

 ldd libv_repExtDPD.so 
on the terminal, I get the following output:

Code: Select all

  linux-vdso.so.1 =>  (0x00007ffce2be8000)
	libopencv_core.so.2.4 => /usr/local/lib/libopencv_core.so.2.4 (0x00007f5184479000)
	libopencv_gpu.so.2.4 => /usr/local/lib/libopencv_gpu.so.2.4 (0x00007f517e247000)
	libopencv_highgui.so.2.4 => /usr/local/lib/libopencv_highgui.so.2.4 (0x00007f517dfb2000)
	libopencv_imgproc.so.2.4 => /usr/local/lib/libopencv_imgproc.so.2.4 (0x00007f517dad6000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f517d8b9000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f517d6b5000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f517d3a3000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f517d0a7000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f517ce90000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f517cad2000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f517c8bb000)
	libcudart.so.7.0 => /usr/local/cuda/lib64/libcudart.so.7.0 (0x00007f517c65e000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f517c456000)
	libGL.so.1 => /usr/lib/nvidia-346/libGL.so.1 (0x00007f517c0fe000)
	libtbb.so.2 => /usr/lib/libtbb.so.2 (0x00007f517bed1000)
	libopencv_calib3d.so.2.4 => /usr/local/lib/libopencv_calib3d.so.2.4 (0x00007f517bbf4000)
	libopencv_objdetect.so.2.4 => /usr/local/lib/libopencv_objdetect.so.2.4 (0x00007f517b973000)
	libnppc.so.7.0 => /usr/local/cuda/lib64/libnppc.so.7.0 (0x00007f517b70c000)
	libnppi.so.7.0 => /usr/local/cuda/lib64/libnppi.so.7.0 (0x00007f5177179000)
	libnpps.so.7.0 => /usr/local/cuda/lib64/libnpps.so.7.0 (0x00007f51769bc000)
	libcublas.so.7.0 => /usr/local/cuda/lib64/libcublas.so.7.0 (0x00007f51749fa000)
	libcufft.so.7.0 => /usr/local/cuda/lib64/libcufft.so.7.0 (0x00007f5170b42000)
	libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f51708f2000)
	libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007f51706ca000)
	libtiff.so.4 => /usr/lib/x86_64-linux-gnu/libtiff.so.4 (0x00007f5170466000)
	libjasper.so.1 => /usr/lib/x86_64-linux-gnu/libjasper.so.1 (0x00007f517020e000)
	libIlmImf.so.6 => /usr/lib/libIlmImf.so.6 (0x00007f516ff4d000)
	libHalf.so.6 => /usr/lib/libHalf.so.6 (0x00007f516fd0a000)
	libgstreamer-0.10.so.0 => /usr/lib/x86_64-linux-gnu/libgstreamer-0.10.so.0 (0x00007f516fa23000)
	libgobject-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007f516f7d4000)
	libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f516f4df000)
	libgstvideo-0.10.so.0 => /usr/lib/x86_64-linux-gnu/libgstvideo-0.10.so.0 (0x00007f516f2c3000)
	libgstapp-0.10.so.0 => /usr/lib/x86_64-linux-gnu/libgstapp-0.10.so.0 (0x00007f516f0b7000)
	libgstriff-0.10.so.0 => /usr/lib/x86_64-linux-gnu/libgstriff-0.10.so.0 (0x00007f516eeaa000)
	libgstpbutils-0.10.so.0 => /usr/lib/x86_64-linux-gnu/libgstpbutils-0.10.so.0 (0x00007f516ec87000)
	libdc1394.so.22 => /usr/lib/x86_64-linux-gnu/libdc1394.so.22 (0x00007f516ea14000)
	libv4l1.so.0 => /usr/lib/x86_64-linux-gnu/libv4l1.so.0 (0x00007f516e80e000)
	libv4l2.so.0 => /usr/lib/x86_64-linux-gnu/libv4l2.so.0 (0x00007f516e602000)
	libavcodec.so.53 => /usr/lib/x86_64-linux-gnu/libavcodec.so.53 (0x00007f516d7f0000)
	libavformat.so.53 => /usr/lib/x86_64-linux-gnu/libavformat.so.53 (0x00007f516d4f0000)
	libavutil.so.51 => /usr/lib/x86_64-linux-gnu/libavutil.so.51 (0x00007f516d2d0000)
	libswscale.so.2 => /usr/lib/x86_64-linux-gnu/libswscale.so.2 (0x00007f516d08a000)
	libQtOpenGL.so.4 => /usr/lib/x86_64-linux-gnu/libQtOpenGL.so.4 (0x00007f516cd8c000)
	libQtGui.so.4 => /usr/lib/x86_64-linux-gnu/libQtGui.so.4 (0x00007f516c0be000)
	libQtTest.so.4 => /usr/lib/x86_64-linux-gnu/libQtTest.so.4 (0x00007f516be98000)
	libQtCore.so.4 => /usr/lib/x86_64-linux-gnu/libQtCore.so.4 (0x00007f516b9c6000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f5184bc2000)
	libnvidia-tls.so.346.46 => /usr/lib/nvidia-346/tls/libnvidia-tls.so.346.46 (0x00007f516b7c3000)
	libnvidia-glcore.so.346.46 => /usr/lib/nvidia-346/libnvidia-glcore.so.346.46 (0x00007f5168aea000)
	libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f51687b5000)
	libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f51685a4000)
	libopencv_flann.so.2.4 => /usr/local/lib/libopencv_flann.so.2.4 (0x00007f5168331000)
	libopencv_features2d.so.2.4 => /usr/local/lib/libopencv_features2d.so.2.4 (0x00007f5168084000)
	libImath.so.6 => /usr/lib/libImath.so.6 (0x00007f5167e7e000)
	libIex.so.6 => /usr/lib/libIex.so.6 (0x00007f5167c5f000)
	libIlmThread.so.6 => /usr/lib/libIlmThread.so.6 (0x00007f5167a58000)
	libgmodule-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007f5167854000)
	libxml2.so.2 => /usr/lib/x86_64-linux-gnu/libxml2.so.2 (0x00007f51674f8000)
	libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f51672f0000)
	libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f51670b3000)
	libgstbase-0.10.so.0 => /usr/lib/x86_64-linux-gnu/libgstbase-0.10.so.0 (0x00007f5166e60000)
	liborc-0.4.so.0 => /usr/lib/x86_64-linux-gnu/liborc-0.4.so.0 (0x00007f5166be5000)
	libgstaudio-0.10.so.0 => /usr/lib/x86_64-linux-gnu/libgstaudio-0.10.so.0 (0x00007f51669ae000)
	libgsttag-0.10.so.0 => /usr/lib/x86_64-linux-gnu/libgsttag-0.10.so.0 (0x00007f5166779000)
	libraw1394.so.11 => /usr/lib/x86_64-linux-gnu/libraw1394.so.11 (0x00007f516656a000)
	libusb-1.0.so.0 => /lib/x86_64-linux-gnu/libusb-1.0.so.0 (0x00007f516635b000)
	libv4lconvert.so.0 => /usr/lib/x86_64-linux-gnu/libv4lconvert.so.0 (0x00007f51660e6000)
	libvpx.so.1 => /usr/lib/libvpx.so.1 (0x00007f5165e41000)
	libvorbisenc.so.2 => /usr/lib/x86_64-linux-gnu/libvorbisenc.so.2 (0x00007f5165972000)
	libvorbis.so.0 => /usr/lib/x86_64-linux-gnu/libvorbis.so.0 (0x00007f5165746000)
	libtheoraenc.so.1 => /usr/lib/x86_64-linux-gnu/libtheoraenc.so.1 (0x00007f5165509000)
	libtheoradec.so.1 => /usr/lib/x86_64-linux-gnu/libtheoradec.so.1 (0x00007f51652ee000)
	libspeex.so.1 => /usr/lib/x86_64-linux-gnu/libspeex.so.1 (0x00007f51650d5000)
	libschroedinger-1.0.so.0 => /usr/lib/libschroedinger-1.0.so.0 (0x00007f5164e22000)
	libgsm.so.1 => /usr/lib/libgsm.so.1 (0x00007f5164c14000)
	libva.so.1 => /usr/lib/x86_64-linux-gnu/libva.so.1 (0x00007f51649fe000)
	libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f51647ee000)
	libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f5164551000)
	libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f5164347000)
	libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f5164111000)
	libaudio.so.2 => /usr/lib/x86_64-linux-gnu/libaudio.so.2 (0x00007f5163ef9000)
	libSM.so.6 => /usr/lib/x86_64-linux-gnu/libSM.so.6 (0x00007f5163cf1000)
	libICE.so.6 => /usr/lib/x86_64-linux-gnu/libICE.so.6 (0x00007f5163ad7000)
	libXi.so.6 => /usr/lib/x86_64-linux-gnu/libXi.so.6 (0x00007f51638c7000)
	libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f51636a9000)
	libgstinterfaces-0.10.so.0 => /usr/lib/x86_64-linux-gnu/libgstinterfaces-0.10.so.0 (0x00007f5163497000)
	libogg.so.0 => /usr/lib/x86_64-linux-gnu/libogg.so.0 (0x00007f5163290000)
	libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f5163066000)
	libXt.so.6 => /usr/lib/x86_64-linux-gnu/libXt.so.6 (0x00007f5162e00000)
	libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f5162bfd000)
	libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f51629f8000)
	libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f51627f2000)
Can anyone find the reason why the crash occurs, looking at these outputs above?
Thanks in advance.

coppelia
Site Admin
Posts: 10360
Joined: 14 Dec 2012, 00:25

Re: V-REP crash when loading plugin with OpenCV

Post by coppelia »

Hello,

the reason for the crash is difficult to say without seeing your code. The crash happens in your plugin v_repStart entry point. Try adding some prints to the console in that routine to see what exactly triggers the crash.

Cheers

marcofe
Posts: 16
Joined: 27 Apr 2015, 14:25

Re: V-REP crash when loading plugin with OpenCV

Post by marcofe »

Thanks for your answer. Actually, I can't check anything because even a print in the first line of the v_repStart function is not shown when V-REP crashes.
I have not so many code lines in my plugin: I simply defined a OpenCV black image cv::Mat at the beginning of the function v_repMessage, and I tried to show it in the if-branch sim_message_eventcallback_modulehandle. About this code, and considering that I installed Opencv 2.4.11 on my Ubuntu, I observed a weird behaviour that can be summarized as follows:

1. If I simply write down the required OpenCV libraries in the linking instruction of my Makefile (e.g -lopencv_core, -lopencv_highgui), the plugin is properly loaded, and when I run the simulation the black image is shown. However, typing

Code: Select all

ldd libv_repExtDPD.so
it is shown that the loaded libraries are related to OpenCV 2.3 (that I never explicitely installed). If I try to link also -lopencv_gpu, the link fails because this lib is not found. This is not good for me because I do need to use the gpu lib.

2. If I specify the path where OpenCV 2.4.11 is supposed to be installed (/usr/local/lib), -lopencv_gpu is found and linked to the target shared library, along with the other 2.4-versioned OpenCV libraries, as verified by ldd command. However, this is the case where the plugin is not loaded and V-REP crashes.

So, apparently the crash seems to be related to the OpenCV version. Could these infos to be helpful to detect the reason of my issue?

coppelia
Site Admin
Posts: 10360
Joined: 14 Dec 2012, 00:25

Re: V-REP crash when loading plugin with OpenCV

Post by coppelia »

Actually just typing

Code: Select all

ldd libv_repExtDPD.so
is not correct, since when you start V-REP with

Code: Select all

./vrep.sh
the library path is modified. So in order to verify your library in the same context as when V-REP is loaded, type

Code: Select all

./libLoadErrorCheck.sh
but first replace the line

Code: Select all

ldd "$dirname/libv_rep.so"
with

Code: Select all

ldd "$dirname/libv_repExtDPD.so"
in that file.

Cheers

marcofe
Posts: 16
Joined: 27 Apr 2015, 14:25

Re: V-REP crash when loading plugin with OpenCV

Post by marcofe »

I tried your suggestion, but it didn't give me new hints to find out the origin of the issue. By the way, after other trials, I observed that the problem is given by the CUDA modules of OpenCV: in fact, V-REP does not crash anymore and the plugin is loaded if OpenCV is built without enabling the CUDA support. If I build OpenCV again with CUDA enabled, then the crash occurs.
Do you know if this is a known issue and/or, what could solve that?

coppelia
Site Admin
Posts: 10360
Joined: 14 Dec 2012, 00:25

Re: V-REP crash when loading plugin with OpenCV

Post by coppelia »

It seems to me something is missing at compile/link time, probably a compilation/linking flag. Since even the plugin load operation crashes before being able to execute a single line of code in the plugin...

Cheers

marcofe
Posts: 16
Joined: 27 Apr 2015, 14:25

Re: V-REP crash when loading plugin with OpenCV

Post by marcofe »

When I used my application outside V-REP I used the same flags and libraries, and the code worked. So I don't think it's a problem of compilation/linking flag missing. Perhaps it could be a problem of V-REP itself with a CUDA-enabled-version of OpenCV. Have you ever tested that?

coppelia
Site Admin
Posts: 10360
Joined: 14 Dec 2012, 00:25

Re: V-REP crash when loading plugin with OpenCV

Post by coppelia »

We have never tested that. I don't know what else could be the reason..

marcofe
Posts: 16
Joined: 27 Apr 2015, 14:25

Re: V-REP crash when loading plugin with OpenCV

Post by marcofe »

I solved my problem. The reason was not related to the CUDA support, but to the QT support. In particular, the version of QT with which OpenCV has been built was different from the version used to build V-REP. Downloading the proper QT version and re-building OpenCV with QT support did the trick.
Thanks for your willingness.
Cheers

coppelia
Site Admin
Posts: 10360
Joined: 14 Dec 2012, 00:25

Re: V-REP crash when loading plugin with OpenCV

Post by coppelia »

oh right, I completely forgot about that possibility! Thanks for the precision.

Cheers

Post Reply