[英]How to fix “Exception thrown: read access violation. **Surface** was nullptr. occurred” in SDL2 C++
Im trying to learn SDL2 with c++,我正在尝试用 C++ 学习 SDL2,
and every time I try to fill a surface i get this error, searched on the internet for a solution and haven`t found one yet:每次我尝试填充表面时都会出现此错误,在互联网上搜索了解决方案,但还没有找到:
SDL_Surface* Surface = NULL;
SDL_FillRect(Surface, NULL, SDL_MapRGB(Surface->format, 0, 255, 0));
every time I run this, it doesn't show an error but it does break the code and shows an X and a little box with the text "Exception thrown: read access violation. Surface was nullptr."每次我运行它时,它都没有显示错误,但它确实破坏了代码并显示了一个 X 和一个带有文本“抛出异常:读取访问冲突。表面为 nullptr”的小框。 near the FillRect line.
在 FillRect 线附近。 I can click "Copy Details" and then it copies "Exception thrown: read access violation. ** Surface ** was nullptr. occurred"
我可以单击“复制详细信息”,然后它会复制“抛出异常:读取访问冲突。** Surface ** 为 nullptr。发生”
You need to use something like你需要使用类似的东西
SDL_CreateRGBSurface
instead for NULL
.而不是
NULL
。 Because you cant write to something that doesn't exist in memory.因为你不能写入内存中不存在的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.