开发者

Memory error in OpenGL-es 2.0 code

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== 
==599开发者_运维知识库7== 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 .


I just want to know that its because of these errors I am getting that screen disappears or something else might be the reason

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:

int i32NumMessages = XPending( x11Display );
for( int i = 0; i < i32NumMessages; i++ )
{
    XEvent  event;
    XNextEvent( x11Display, &event );
}

That loop is in fact

  • obviously wrong
  • the reason your application (almost) immediately exits

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜