Application crash when using CUDA

I’ve recently installed CUDA 2.1 and wanted to add CUDA background extraction implementation to my computer vision application (that uses also IPP and OpenCV with it’s gui). But when I add even one line of CUDA-related code (even something simple like “cudaSetDevice(0)”), application crashes on exit in __crtExitProcess with the following message: “Unhandled exception at 0x064ab809 in Prototype.exe: 0xC0000005: Access violation reading location 0x06996804”. With any calls to CUDA removed application works just fine. That’s not only sad but it also prevents me from using CUDA visual debugger.

Have you ever face something like that? Any suggestions?

Btw, SDK samples work just fine.

Thanks in advance.

Today I’ve decided to investigate what’s happening.
First of all, I’ve removed all the code except of cudaSetDevice(0) from my program. It had crashed still.
Next, I’ve changed all the project settings to the same as in SDK cppIntegration project assuming there is something wrong with code generation or linking in my project. It hadn’t helped at all.

Looking closer to the crash call stack I’ve found that actual crash happens in module nvd3dum.dll. That’s call stack print:

nvd3dum.dll!02bfb809() 	
[Frames below may be incorrect and/or missing, no symbols loaded for nvd3dum.dll]	
ddraw.dll!60e66bd2() 	
ddraw.dll!60e66b50() 	
ddraw.dll!60e66c60() 	
ddraw.dll!60e66cca() 	
ddraw.dll!60e6689f() 	
nvcuda.dll!00b819e6() 	
nvcuda.dll!00b87343() 	
nvcuda.dll!00b840a4() 	
ntdll.dll!779183b4() 	
kernel32.dll!76eac350() 	
kernel32.dll!76eac379() 	
ddraw.dll!60e662ea() 	
opengl32.dll!5f22a198() 	
opengl32.dll!5f22a354() 	
ntdll.dll!778fe1c4() 	
ntdll.dll!778ea8dd() 	

msvcr90d.dll!doexit(int code=0, int quick=0, int retcaller=0) Line 644 + 0x9 bytes C
msvcr90d.dll!exit(int code=0) Line 412 + 0xd bytes C

The strangest thing about all this stuff is that my project crashes on exit even when it is almost similar to the cppIntegration sample. I can’t understand where is the difference between the projects.

Please, I need some good advice. Solving this problem is quite important for me right now.

Btw, I’m using VS2008 SP1 to compile my project.

Have you tried copying the template project and using that as a base for your CUDA code? I found it rather hard to get CUDA running when compiling from VS, after adding CUDA code to an existing project.

My actual CUDA project is lib, not an application. So I can’t use an existing template =(