Page 1 of 1

Possible heap corruption (CameraSDK 1.1.3Final, VS2008)

Posted: Thu Jan 10, 2013 6:38 pm
by sdgnovb
Hi.

I've been trying to include the CameraSDK into my project,
but got strange bugs where I could not allocate any memory anymore.

Tracking them down, I reached this point:

Code: Select all

int main(int argc, char *argv[])
{
	printf("-> malloc 1 :: %X \n",malloc(1)); // <-- this will return a valid memory address	
	CameraManager::X();
	printf("-> malloc 2 :: %X \n",malloc(1)); // <-- THIS RETURNS NULL
	exit(0);
}
Please don't comment on style or proper use of malloc or CameraManager. This is just an example to show that after calling X() or its member functions, malloc will only return null pointers.

That means trying to access the cameraSDK either severely corrupts the heap or does some other kind of magic to break malloc.

I'm using windows7 (64bit), and the project is a VS2008 32bit application.
I compile it with /MT (ie: static runtime library)(because I read on the forums that CameraLibrary is compiled with /MT), and do not get any library-incompatibility warnings.
(I have tried using /MD earlier, but that didn't work either).

I have currently only used CameraSDK 1.1.3Final.

What could be the source of this?

Re: Possible heap corruption (CameraSDK 1.1.3Final, VS2008)

Posted: Sat Jan 12, 2013 8:51 pm
by sdgnovb
I found the solution myself now:
Apparently the preprocessor definition CAMERALIBRARY_IMPORTS must be set before including the CameraLibrary headers.

I would like to point out that this is NOT DOCUMENTED ANYWHERE
and is extremely difficult to track down!

"Malloc always returning NULL pointers" is a very bad way of telling the user: "you forgot to define the completely arbitrary random secret magic word".
You don't even allow dll-free static linking, so fixing this in cameracommonglobals.h takes 5 seconds (change the default behavior)!
Please do it and save your customers a lot of time!

(NA) Re: Possible heap corruption (CameraSDK 1.1.3Final, VS2008)

Posted: Mon Jan 14, 2013 1:57 pm
by NaturalPoint - Brent
Hi SebastianG,

We're continuing to improve our Camera SDK and as of the next public version we will have native built libraries for 2005, 2008, and 2010 both for 32 & 64bit with both static and dynamic run-time linkage. Here's a list of libraries that will be in there:

http://i.imgur.com/y8ux9.jpg

Unfortunately, only dynamic link libraries are available currently through the Camera SDK although we do use the static linked versions internally. If you want the static linked versions just let us know and we'll take that into consideration. I'd personally like to offer them so knowing users like you would like them is just more validation for that feature.

The problem with heap allocation usually stems from the application and the linked in libraries linking to different versions of the run-time. I apologize for the time wasted and please ping us with questions if something is becoming a time sink. We want this to be quick & easy for you as well as reliable. We're continuing to make improvements. Please let us know if we can do anything else.

Re: (NA) Re: Possible heap corruption (CameraSDK 1.1.3Final, VS2008)

Posted: Mon Jan 14, 2013 6:08 pm
by sdgnovb
Dear Brent,

thank you for your answer, but this has nothing to do with the problem and is not the solution.

Please publish my previous comment explaining the solution, so that other developers can find it. I am sure there are many that don't just use your sample projects.

Again:
The preprocessor definition "CAMERALIBRARY_IMPORTS" must be set before including the CameraLibrary headers.

Regards,
Max