- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
当我尝试使用 openGL 生成纹理时,我在该方法中遇到了段错误:
void RendererGL::create_gl(SDL_Surface * surf, GLuint * tex ) {
GLenum format; GLint colors_amount = surf->format->BytesPerPixel;
if (colors_amount == 4) {
if (surf->format->Rmask == 0x000000ff)
format = GL_RGBA;
else
format = GL_BGRA;
}
else if (colors_amount == 3) {
if (surf->format->Rmask == 0x000000ff)
format = GL_RGB;
else
format = GL_BGR;
}
else {
gCritical("Image is not truecolor");
}
glGenTextures( 1, tex );
glBindTexture( GL_TEXTURE_2D, *tex );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D( GL_TEXTURE_2D, 0, colors_amount, surf->w, surf->h, 0, format,
GL_UNSIGNED_BYTE, surf->pixels ); }
我只在带有 nvidia 驱动程序的 debian 上遇到过这个问题。使用开源驱动程序应用程序可以正常运行。 Valgrind 测试返回:
[ Info ] RendererGL::Init GL
==13033== Thread 3:
==13033== Invalid read of size 8
==13033== at 0x51293C9: ??? (in /usr/lib/x86_64-linux-gnu/nvidia/current/libGL.so.304.64)
==13033== by 0x419B0F: RendererGL::initGL() (RendererGL.cpp:12)
==13033== by 0x41036C: Renderer::Renderer() (Renderer.cpp:27)
==13033== by 0x4058EA: Renderer::getInstance() (Renderer.hpp:17)
==13033== by 0x40B648: StandardReferences::StandardReferences() (StandardReferences.hpp:13)
==13033== by 0x414C26: Map::Map(short**, unsigned short, unsigned int, unsigned int) (Map.cpp:8)
==13033== by 0x4136E4: MapManager::loadMapFromFile(std::string, short) (MapManager.cpp:82)
==13033== by 0x4138A0: MapManager::load() (MapManager.cpp:97)
==13033== by 0x4084BA: Resource::load() (Resource.cpp:36)
==13033== by 0x4196AF: Splash::initThread(void*) (Splash.cpp:99)
==13033== by 0x53D0405: ??? (in /usr/lib/x86_64-linux-gnu/libSDL-1.2.so.0.11.4)
==13033== by 0x5413898: ??? (in /usr/lib/x86_64-linux-gnu/libSDL-1.2.so.0.11.4)
==13033== Address 0x658 is not stack'd, malloc'd or (recently) free'd
==13033==
==13033==
==13033== HEAP SUMMARY:
==13033== in use at exit: 22,104,451 bytes in 31,729 blocks
==13033== total heap usage: 47,499 allocs, 15,770 frees, 54,869,707 bytes allocated
==13033==
==13033== LEAK SUMMARY:
==13033== definitely lost: 833 bytes in 8 blocks
==13033== indirectly lost: 1,728 bytes in 38 blocks
==13033== possibly lost: 269,732 bytes in 99 blocks
==13033== still reachable: 21,832,158 bytes in 31,584 blocks
==13033== suppressed: 0 bytes in 0 blocks
==13033== Rerun with --leak-check=full to see details of leaked memory
==13033==
==13033== For counts of detected and suppressed errors, rerun with: -v
==13033== Use --track-origins=yes to see where uninitialised values come from
==13033== ERROR SUMMARY: 12 errors from 2 contexts (suppressed: 6 from 6)
最佳答案
我敢打赌它是 RGB 表面的段错误,而不是 RGBA 表面。
尝试 glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
在您的 glTexImage2D()
调用之前。
GL_UNPACK_ALIGNMENT
默认为 4,这适用于 RGBA 数据,但会导致 OpenGL 读取 RGB 表面的 surf->pixels
的末尾。
你必须使用 GL_UNPACK_ROW_LENGTH
如果 surf->pitch
不为零。
关于c++ - SDL、OpenGL : Segmentation fault,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13369861/
我在一个俄罗斯编程论坛上遇到了这个问题,但还没有想出一个优雅的解决方案。 问题: 你有一个包含N个正整数的数组,你需要将它分成M个连续的段,使得最大段的和是可能的最小值。通过段的总数,我的意思是它所有
我正在从文本“从 0 到 1 的操作系统”中学习链接脚本,并且在文本中他们展示了一个使用关键字 PHDRS 的示例; ENTRY(main); PHDRS { headers PT_P
一个小型测试程序在 64 位 Linux 上使用 gfortran (4.4.5) 返回段错误。 n=2_8**22_8 时不存在故障。 gdb 指示在循环的第一次迭代期间函数 mylen 中发生段错
我正在尝试计算一个比率,当我的分子数组充满 0 时它可以工作,但是当我在分子数组中有值时会中断程序。 223 Double_t *ratio_calculations(int bin_numbers,
我正在研究组合分页/分段系统,在我的书中有两种方法: 1.paged segmentation 2.segmented paging 我无法弄清楚两者之间的区别。我认为在分页分段中,段被分成页面,在分
语义分割只是一种重复,还是“语义分割”和“分割”之间有区别? “场景标记”和“场景解析”有区别吗? 像素级分割和像素级分割有什么区别? (附带问题:当您拥有这种逐像素注释时,您是否可以免费获得对象检测
我遇到了一个非常奇怪的行为,我正在遵循在线文档,并且在创建一个段来与我的子段一起使用时,lambda 按以下顺序执行: xray_recorder.begin_segment('segment-nam
我们正在我们的服务器上进行一些负载测试,我正在使用 tshark 将一些数据捕获到 pcap 文件,然后使用 wireshark GUI 通过转到 Analyze -> expert Info 来查看
我是一名高中生,今年开始学习汇编。 我目前正在制作 Pacman 克隆作为我的最终项目。 我遇到的唯一问题是我的代码很大,*.exe 文件几乎有 64KB。 所以我的问题是,如果我转向模型介质,我需要
前言 本系列文章是博主在工作中使用SAM模型时的学习笔记,包含三部分: SAM初步理解,简单介绍模型框架,不涉及细节和代码 SAM细节理解,对各模块结合代码进一步分析 SAM微调实例
我很困惑进程在使用虚拟内存时如何可能出现段错误。据我了解,“虚拟”内存允许进程访问所有可用内存,然后将其映射到“实际”硬件内存。通过这种转换,进程怎么可能尝试访问不允许访问的内存部分? 最佳答案 听起
Tritwise操作(向右旋转和疯狂操作)无法正确运行,并在Malbolge编译器/解释器中引发分段错误。 在看到有关Coding Challenges和Code Golf的惊人答案之后,我决定开始在
只是有关DirectX11镶嵌的问题。 在“船体着色器”中,可以设置的最大镶嵌因子为64(不确定原因)。现在,尽管对于小型飞机已经足够了,但是对于大型飞机来说,这还远远不够,所以我想知道如何渲染大型飞
我需要在 matlab 中手动分割图像。我很想使用“impoly”,但我主要需要分割圆形对象。 我在 Youtube 上的 Ali Pashaei 视频中找到了我需要的东西,在“FlowImagePr
我有下面的代码。当我取消注释 temperature(i,j) = anode_temperature 时,我会出现 SegFault。 forall(i=0:Cells(1), j=0:Cells(
我是 C 编程新手,我的代码中出现了段错误。该程序使用返回函数来询问用户他们的银行帐户中有多少钱。稍后我将添加代码来计算利息。感谢您为我查看此内容,因为我很难找出为什么会出现此错误。 #include
为了测试,我编写了一个代码来计算 #include int main(void) { int p, i, primes[50], index; boo
这个问题已经有答案了: What is a segmentation fault? (17 个回答) 已关闭 5 年前。 最近我开始研究内置函数,但遇到了一个错误,那就是: 为什么我会遇到此程序段错误
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
注意:我们有很多段错误,基本相同 答案,所以我试图将其分解为一个规范的问题,例如 我们有undefined reference。 尽管我们有一个关于what a segmentati
我是一名优秀的程序员,十分优秀!