I wanted to practice using CUDA for collision detection in an SDL program. I started in Visual Studio with a CUDA Runtime Solution and copied in existing SDL files that I had, set up the linker/properties, commented out the cuda_runtime.h include. There is currently no CUDA code in my source files. Using kernel.cu as the file with my main function. I have a problem declaring/assigning variables in a specific class.
I have tried running the same files outside of a CUDA project using main.cpp instead of kernel.cu and have no problems whatsoever. The CUDA project also runs as expected when this class is not used.
I have a class MSDL_FPS dedicated to showing the current running FPS. Two such methods of the class is as follows:
void MSDL_FPS::render() {
Uint32 elapsed = SDL_GetTicks() - initial;
Uint32 fps = (int)(frames / (elapsed / 1000.0));
if(fps != old_fps) {
old_fps = fps;
std::string text("FPS : ");
text = text + std::to_string(fps);
makeTexture(text);
}
...
}
void MSDL_FPS::makeTexture(std::string text) {
if(texture != nullptr)
SDL_DestroyTexture(texture);
int mwidth = 0;
int mheight = 0;
for(char& c : text) {
int k = (int)c - 32;
mwidth = mwidth + width[k];
if(height[k] > mheight)
mheight = height[k];
}
...
}
This is its relevant uses in the main function
MSDL_FPS* showFPS = new MSDL_FPS(main_window, 10, 10, 20);
...
while(!quit){
...
showFPS->update();
showFPS->render();
}
The update method merely increments the frames counter.
I have also tried the following with no success.
MSDL_FPS showFPS(main_window, 10, 10, 20);
Expected no issues as it runs outside of the CUDA project and I'm not experienced enough with CUDA to figure out what's causing the issue.
Project builds but throws the following exception at runtime on the line
int mwidth = 0;
Call Stack
SDL2.dll!000000006c77725c()
PerPixelCudaCheck.exe!MSDL_FPS::makeTexture(std::basic_string<char,std::char_traits<char>,std::allocator<char> > text)
PerPixelCudaCheck.exe!MSDL_FPS::render()
PerPixelCudaCheck.exe!SDL_main(int argc, char * * argv)
PerPixelCudaCheck.exe!main_getcmdline(...)
[External Code]
Exception thrown at 0x000000006C77725C (SDL2.dll) in PerPixelCudaCheck.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
User contributions licensed under CC BY-SA 3.0