简体   繁体   English

如何修复“抛出异常:读取访问冲突。 **Surface** 为 nullptr。 在 SDL2 C++ 中发生”

[英]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.

相关问题 C ++ Battle4Zion项目引发未处理的异常:读取访问冲突。 **这**是nullptr。 发生了 - C++ Battle4Zion project Unhandled exception thrown: read access violation. **this** was nullptr. occurred C++ 如何修复抛出的异常:写访问冲突。 这是空指针。 20号线 - C++ How do I fix Exception thrown: write access violation. this was nullptr. on Line 20 引发异常:读取访问冲突。 此-> m_pRenderTarget为nullptr。 C ++ - Exception thrown: read access violation. this->m_pRenderTarget was nullptr. c++ “抛出异常:读取访问冲突。 this->head 是 nullptr。” - “Exception thrown: read access violation. this->head was nullptr.” 如何解决“抛出未处理的异常:读取访问冲突。 this->cc._Ptr 是 nullptr。” 错误[暂停] - How to fix “Unhandled exception thrown: read access violation. this->cc._Ptr was nullptr.” error [on hold] (SDL渲染问题)C ++异常抛出:读取访问冲突。 这是nullptr - (SDL Render Problem) C++ Exception Thrown: read access violation. THIS was nullptr 抛出C ++异常:读取访问冲突。 这是nullptr - C++ Exception thrown: read access violation. this was nullptr C ++-引发异常:读取访问冲突。 变量为nullptr - C++ - Exception thrown: read access violation. Variable was nullptr 抛出异常:读取访问冲突。 这是 nullptr - Exception thrown: read access violation. this was nullptr 抛出异常:写访问冲突。 这是 nullptr (C++) - Exception thrown: write access violation. this was nullptr (C++)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM