0

I am creating a console application using openCV 2.4.11 technologies where I am trying to create 30+ images from a single image using perspective transformations.

I am using matt classes instead of IPLimages.

The debug and release version of the console application work, however the .exe file in the project/release folder crashes.

What could the possible reasons for this different behavior be?

I should mention that the release version works as well, its only the .exe file that crashes after generating a few pictures.

Vrankela
  • 1,162
  • 3
  • 16
  • 39
  • 1
    You are asking for speculation/opinions (so your question will be closed); That said, a possible reason for the crash in release only, is undefined behavior in your application. – utnapistim Mar 30 '15 at 08:17
  • possible duplicate of [What are some reasons a Release build would run differently than a Debug build](http://stackoverflow.com/questions/312312/what-are-some-reasons-a-release-build-would-run-differently-than-a-debug-build) – Tom Moers Mar 30 '15 at 08:20
  • What do you by *the console application work, however the .exe file [...] crashes*? Aren't they one and the same? After your last edit I tend to agree with @utnapistim's comment above. – nils Mar 30 '15 at 09:07
  • please check whether `mat.empty()` is true for any of your inputs. If that is the case, your program might use different pathes when you execute the .exe or start your project from within your development environment which causes the program to crash (tries to access a Mat that couldnt be found/read). – Micka Mar 30 '15 at 09:22
  • @Micka that didnt resolve my issue... but thank you for the effort. – Vrankela Mar 30 '15 at 10:01
  • @nils the difference is that I am doing the release and debug from visual studio (where it works just fine) but the .exe file is stand alone and it crashes. – Vrankela Mar 30 '15 at 10:09
  • run the debug .exe version and tell me your error message please – Micka Mar 30 '15 at 10:57
  • @Micka the exe simply crashes but the last message in the consol is: OepnCV error: Insufficient memory in cv::OutOfMemoryError, file ..\\core\src\alloc.src ln52 ----!The number of bytes is always different ----- – Vrankela Mar 30 '15 at 12:27
  • whenever you create a Mat or previously unknown size (e.g. during tracking, perspective warping or sth), can you first check the dimensions please? you try to create a 3,5 GB object... and do you use mutli-threading? "OepnCV error" looks like there is an "e" print in another thread. – Micka Mar 30 '15 at 14:15
  • @Micka I dont use multithreading. – Vrankela Mar 31 '15 at 06:51

2 Answers2

3

This problem could be related to differences in the memory layout between the release and debug mode when using the Visual Studio compiler (possibly other compilers, too).

Informally speaking, the debug mode adds a certain amount of memory around each of your objects stored in memory. Sort of a padding, if you will. Since your out-of-bound access, which creates a segmentation fault in release mode, may fall into this padding area, no segmentation fault will be triggered (more details).

Nevertheless, this is a bug in your code and should be fixed, e.g. by adding checks for null pointers and out-of-bound access using assert.

nils
  • 2,424
  • 1
  • 17
  • 31
  • 2
    Other things to check: bad timing when starting threads (e.g. starting a thread and assuming it is fully initialized on the next instruction), uninitialized variable access (presumably they will have different values if uninitialized between debug and release) and fix any compilation warnings. – utnapistim Mar 30 '15 at 08:35
  • @utnapistim Agreed. These things should be checked, too. – nils Mar 30 '15 at 09:08
0

I came to a solution, I simply started from the beginning by initializing all the matrices and the .exe file is now working (although Im still not sure what i messed up the first time). Thank you everyone for your contributions.

Vrankela
  • 1,162
  • 3
  • 16
  • 39