OpenGL-es 2.0 代码中的内存错误
我已经在 Ubuntu 10.10 中使用 PVRSDK 在 OpenGL-ES 2.0 中编写了代码,现在的问题是,无论我想要什么输出,我都能得到它,但它出现了,然后窗口消失了, 如果我设置一个断点,我就会得到我想要的。但我不明白为什么窗口消失了。
当我用 valgrind 进行内存检查时,我得到了这些错误:
==5997== Memcheck, a memory error detector
==5997== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==5997== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==5997== Command: ./cube
==5997==
libEGL warning: use software fallback
==5997==
==5997== HEAP SUMMARY:
==5997== in use at exit: 12,126 bytes in 94 blocks
==5997== total heap usage: 97,499 allocs, 97,405 frees, 197,353,970 bytes allocated
==5997==
==5997== 8 bytes in 1 blocks are definitely lost in loss record 3 of 57
==5997== at 0x4024F12: calloc (vg_replace_malloc.c:467)
==5997== by 0x486CE90: __glXInitialize (glxinit.c:584)
==5997== by 0x486AA61: x11_screen_support (x11_screen.c:133)
==5997== by 0x486DEEB: x11_create_dri2_display (native_dri2.c:700)
==5997== by 0x4869AEA: native_create_display (native_x11.c:42)
==5997== by 0x4866A2A: egl_g3d_initialize (egl_g3d.c:498)
==5997== by 0x4176F36: _eglMatchDriver (egldriver.c:580)
==5997== by 0x4170BBF: eglInitialize (eglapi.c:294)
==5997== by 0x8049EFF: main (Hello.cpp:231)
==5997==
==5997== 40 bytes in 1 blocks are definitely lost in loss record 31 of 57
==5997== at 0x4026351: operator new(unsigned int) (vg_replace_malloc.c:255)
==5997== by 0x8049CE3: main (Hello.cpp:206)
==5997==
==5997== 72 bytes in 1 blocks are definitely lost in loss record 34 of 57
==5997== at 0x4024F12: calloc (vg_replace_malloc.c:467)
==5997== by 0x4A50C7C: st_bufferobj_alloc (st_cb_bufferobjects.c:56)
==5997== by 0x49A1B78: _mesa_alloc_shared_state (shared.c:94)
==5997== by 0x498860F: _mesa_initialize_context_for_api (context.c:904)
==5997== by 0x49886DB: _mesa_create_context_for_api (context.c:1050)
==5997== by 0x49C7479: st_create_context (st_context.c:176)
==5997== by 0x4985A80: st_api_create_context (st_manager.c:646)
==5997== by 0x4868843: egl_g3d_create_context (egl_g3d_api.c:131)
==5997== by 0x4173127: eglCreateContext (eglapi.c:413)
==5997== by 0x804A039: main (Hello.cpp:261)
==5997==
==5997== 1,546 (48 direct, 1,498 indirect) bytes in 1 blocks are definitely lost in loss record 55 of 57
==5997== at 0x4025BD3: malloc (vg_replace_malloc.c:236)
==5997== by 0x4BABD13: talloc_enable_null_tracking (in /usr/lib/libtalloc.so.2.0.1)
==5997== by 0x4BABE28: talloc_init (in /usr/lib/libtalloc.so.2.0.1)
==5997== by 0x49F48B5: glsl_symbol_table::glsl_symbol_table() (glsl_symbol_table.cpp:60)
==5997== by 0x49F2566: _mesa_glsl_parse_state::_mesa_glsl_parse_state(__GLcontextRec*, unsigned int, void*) (glsl_parser_extras.cpp:50)
==5997== by 0x49D68B3: _mesa_glsl_compile_shader (ir_to_mesa.cpp:2815)
==5997== by 0x49A0486: _mesa_CompileShaderARB (shaderapi.c:807)
==5997== by 0x804A0E1: main (Hello.cpp:280)
==5997==
==5997== LEAK SUMMARY:
==5997== definitely lost: 168 bytes in 4 blocks
==5997== indirectly lost: 1,498 bytes in 28 blocks
==5997== possibly lost: 0 bytes in 0 blocks
==5997== still reachable: 10,460 bytes in 62 blocks
==5997== suppressed: 0 bytes in 0 blocks
==5997== Reachable blocks (those to which a pointer was found) are not shown.
==5997== To see them, rerun with: --leak-check=full --show-reachable=yes
==5997==
==5997== For counts of detected and suppressed errors, rerun with: -v
==5997== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 54 from 11)
现在他们提到的那些行:
206 x11Visual = new XVisualInfo;
207 XMatchVisualInfo( x11Display, x11Screen, i32Depth, TrueColor, x11Vis ual);
208 if (!x11Visual)
209 {
210 printf("Error: Unable to acquire visual\n");
211 goto cleanup;
212 }
===========================================================================================
230 EGLint iMajorVersion, iMinorVersion;
231 if (!eglInitialize(eglDisplay, &iMajorVersion, &iMinorVersion))
232 {
233 printf("Error: eglInitialize() failed.\n");
234 }
==========================================================================================
eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, ai32Conte xtAttribs);
262 if (!TestEGLError("eglCreateContext"))
263 {
264 goto cleanup;
265 }
============================================================================================
279 glShaderSource(uiFragShader, 1, (const char**)&pszFragShader, NULL);
280 glCompileShader(uiFragShader);
所以我只想知道,由于这些错误,我得到的屏幕消失了,或者其他原因可能是原因。
I have written a code in OpenGL-ES 2.0 with PVRSDK in Ubuntu 10.10 , now the thing is that whatever output I want , I am getting that but it comes and then the window disappears ,
If I put a break-point I am getting what I want. But I don't understand why the window disappears .
When I do the memory check with valgrind I got these errors :
==5997== Memcheck, a memory error detector
==5997== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==5997== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==5997== Command: ./cube
==5997==
libEGL warning: use software fallback
==5997==
==5997== HEAP SUMMARY:
==5997== in use at exit: 12,126 bytes in 94 blocks
==5997== total heap usage: 97,499 allocs, 97,405 frees, 197,353,970 bytes allocated
==5997==
==5997== 8 bytes in 1 blocks are definitely lost in loss record 3 of 57
==5997== at 0x4024F12: calloc (vg_replace_malloc.c:467)
==5997== by 0x486CE90: __glXInitialize (glxinit.c:584)
==5997== by 0x486AA61: x11_screen_support (x11_screen.c:133)
==5997== by 0x486DEEB: x11_create_dri2_display (native_dri2.c:700)
==5997== by 0x4869AEA: native_create_display (native_x11.c:42)
==5997== by 0x4866A2A: egl_g3d_initialize (egl_g3d.c:498)
==5997== by 0x4176F36: _eglMatchDriver (egldriver.c:580)
==5997== by 0x4170BBF: eglInitialize (eglapi.c:294)
==5997== by 0x8049EFF: main (Hello.cpp:231)
==5997==
==5997== 40 bytes in 1 blocks are definitely lost in loss record 31 of 57
==5997== at 0x4026351: operator new(unsigned int) (vg_replace_malloc.c:255)
==5997== by 0x8049CE3: main (Hello.cpp:206)
==5997==
==5997== 72 bytes in 1 blocks are definitely lost in loss record 34 of 57
==5997== at 0x4024F12: calloc (vg_replace_malloc.c:467)
==5997== by 0x4A50C7C: st_bufferobj_alloc (st_cb_bufferobjects.c:56)
==5997== by 0x49A1B78: _mesa_alloc_shared_state (shared.c:94)
==5997== by 0x498860F: _mesa_initialize_context_for_api (context.c:904)
==5997== by 0x49886DB: _mesa_create_context_for_api (context.c:1050)
==5997== by 0x49C7479: st_create_context (st_context.c:176)
==5997== by 0x4985A80: st_api_create_context (st_manager.c:646)
==5997== by 0x4868843: egl_g3d_create_context (egl_g3d_api.c:131)
==5997== by 0x4173127: eglCreateContext (eglapi.c:413)
==5997== by 0x804A039: main (Hello.cpp:261)
==5997==
==5997== 1,546 (48 direct, 1,498 indirect) bytes in 1 blocks are definitely lost in loss record 55 of 57
==5997== at 0x4025BD3: malloc (vg_replace_malloc.c:236)
==5997== by 0x4BABD13: talloc_enable_null_tracking (in /usr/lib/libtalloc.so.2.0.1)
==5997== by 0x4BABE28: talloc_init (in /usr/lib/libtalloc.so.2.0.1)
==5997== by 0x49F48B5: glsl_symbol_table::glsl_symbol_table() (glsl_symbol_table.cpp:60)
==5997== by 0x49F2566: _mesa_glsl_parse_state::_mesa_glsl_parse_state(__GLcontextRec*, unsigned int, void*) (glsl_parser_extras.cpp:50)
==5997== by 0x49D68B3: _mesa_glsl_compile_shader (ir_to_mesa.cpp:2815)
==5997== by 0x49A0486: _mesa_CompileShaderARB (shaderapi.c:807)
==5997== by 0x804A0E1: main (Hello.cpp:280)
==5997==
==5997== LEAK SUMMARY:
==5997== definitely lost: 168 bytes in 4 blocks
==5997== indirectly lost: 1,498 bytes in 28 blocks
==5997== possibly lost: 0 bytes in 0 blocks
==5997== still reachable: 10,460 bytes in 62 blocks
==5997== suppressed: 0 bytes in 0 blocks
==5997== Reachable blocks (those to which a pointer was found) are not shown.
==5997== To see them, rerun with: --leak-check=full --show-reachable=yes
==5997==
==5997== For counts of detected and suppressed errors, rerun with: -v
==5997== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 54 from 11)
Now those lines which they are mentioning :
206 x11Visual = new XVisualInfo;
207 XMatchVisualInfo( x11Display, x11Screen, i32Depth, TrueColor, x11Vis ual);
208 if (!x11Visual)
209 {
210 printf("Error: Unable to acquire visual\n");
211 goto cleanup;
212 }
===========================================================================================
230 EGLint iMajorVersion, iMinorVersion;
231 if (!eglInitialize(eglDisplay, &iMajorVersion, &iMinorVersion))
232 {
233 printf("Error: eglInitialize() failed.\n");
234 }
==========================================================================================
eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, ai32Conte xtAttribs);
262 if (!TestEGLError("eglCreateContext"))
263 {
264 goto cleanup;
265 }
============================================================================================
279 glShaderSource(uiFragShader, 1, (const char**)&pszFragShader, NULL);
280 glCompileShader(uiFragShader);
So I just want to know that its because of these errors I am getting that screen disappears or something else might be the reason .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
后者的原因。泄漏不会影响程序运行时(除非它们太大以至于程序在需要时无法分配更多内存;但泄漏很小)。
您是否忘记进入 X 事件循环?
更新:
该循环实际上
您只处理到目前为止排队的事件(这可能是极少数的事件)事件)。而你实际上正在丢弃它们。您可能需要编写类似于 this 的内容。
The latter. Leaks do not affect program runtime (unless they are so large that the program fails to allocate more memory when it needs it; but your leaks are small).
Did you forget to enter the X event loop?
Update:
That loop is in fact
You are processing only the events queued so far (which is likely a very small number of events). And you are actually discarding them. You'll probably want to write something like this instead.