0xC0000005: 读取位置 0x0000000000000000 时发生访问冲突 异常处理问题解决办法

典型的空指针错误,

一点要先判断该指针是否为空才操纵。


1.运行一个OpenGL/CUDA相结合的样例程序,main.cpp编译成功。运行可执行文件图形界面无法成功运行,调试过程中显示在glBindBuffer函数处程序报错。 2.main.cpp代码: ``` #include "kernel.h" #include <stdio.h> #include <stdlib.h> #ifdef _WIN32 #define WINDOWS_LEAN_AND_MEAN #define NOMINMAX #include <windows.h> #endif #ifdef __APPLE__ #include<GLUT/glut.h> #else #include <GL/glew.h> #include <GL/freeglut.h> #endif #include <cuda_runtime.h> #include <cuda_gl_interop.h> #include "interactions.h" //texture and pixel objects GLuint pbo = 0;//OpenGL pixel buffer object GLuint tex = 0;//OpenGL texture object struct cudaGraphicsResource *cuda_pbo_resource; void render() { uchar4 *d_out = 0; cudaGraphicsMapResources(1, &cuda_pbo_resource, 0); cudaGraphicsResourceGetMappedPointer((void**)&d_out, NULL, cuda_pbo_resource); kernelLauncher(d_out,W, H, loc); cudaGraphicsUnmapResources(1, &cuda_pbo_resource, 0); } void drawTexture() { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, W, H, 0, GL_RGBA,GL_UNSIGNED_BYTE,NULL); glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(0, 0); glTexCoord2f(0.0f, 1.0f); glVertex2f(0, H); glTexCoord2f(1.0f, 1.0f); glVertex2f(W, H); glTexCoord2f(1.0f, 0.0f); glVertex2f(W, 0); glEnd(); glDisable(GL_TEXTURE_2D); } void display() { render(); drawTexture(); glutSwapBuffers(); } void initGLUT(int *argc, char** argv) { glutInit(argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowSize(W,H); glutCreateWindow(TITLE_STRING); #ifdef __APPLE__ glewInit(); #endif } void initPixelBuffer() { GLuint pbo = 0; glGenBuffers(1, &pbo); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); glBufferData(GL_PIXEL_UNPACK_BUFFER, 4 * W * H * sizeof(GLubyte), 0, GL_STREAM_DRAW); GLuint tex = 0; glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); cudaGraphicsGLRegisterBuffer(&cuda_pbo_resource, pbo, cudaGraphicsMapFlagsWriteDiscard); } void exitfunc() { if (pbo) { cudaGraphicsUnregisterResource(cuda_pbo_resource); glDeleteBuffers(1, &pbo); glDeleteTextures(1, &tex); } } int main(int argc,char** argv) { printInstructions(); initGLUT(&argc, argv); gluOrtho2D(0, W, H, 0); glutKeyboardFunc(keyboard); glutSpecialFunc(handleSpecialKeypress); glutPassiveMotionFunc(mouseMove); glutMotionFunc(mouseDrag); glutDisplayFunc(display); initPixelBuffer(); glutMainLoop(); atexit(exitfunc); return 0; } ``` 3.报错信息:0x0000000000000000 处(位于 dist_2d_cuda.exe 中)引发的异常: 0xC0000005: 执行位置 0x0000000000000000 发生访问冲突。 请问具体是什么问题呢,向各位求助~
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页