# EGL\_BAD\_ALLOC Error

**URL:** <https://forums.imgtec.com/t/egl-bad-alloc-error/562>\
**Category:** PowerVR Insider\
**Created:** [December 11, 2009, 1:58am UTC](https://forums.imgtec.com/t/egl-bad-alloc-error/562 "2009-12-11T01:58:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wangsheng](https://avatars.discourse-cdn.com/v4/letter/w/e36b37/32.png) [@wangsheng](https://forums.imgtec.com/u/wangsheng)\
**Post date:** [December 11, 2009, 1:58am UTC](https://forums.imgtec.com/t/egl-bad-alloc-error/562/1 "2009-12-11T01:58:54Z")

</div>

i want to Draw 2D in my windows , so i&nbsp; use the function Delete gles surfase(eglDestroySurface) , but when return 3D Draw,&nbsp; i use the functon recreate the surface is failed(eglCreateWindowSurface), the error code is EGL\_BAD\_ALLOC. what can i do now?

thanks!

---

<div class="post-metadata">

**Author:** ![wangsheng](https://avatars.discourse-cdn.com/v4/letter/w/e36b37/32.png) [@wangsheng](https://forums.imgtec.com/u/wangsheng)\
**Post date:** [December 11, 2009, 1:59am UTC](https://forums.imgtec.com/t/egl-bad-alloc-error/562/2 "2009-12-11T01:59:40Z")

</div>

&nbsp;void DeleteSurface(void)  
&nbsp;{  
&nbsp;&nbsp;if(m\_eglSurface != EGL\_NO\_SURFACE)  
&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;glFlush();   
&nbsp;&nbsp;&nbsp;eglMakeCurrent(m\_eglDisplay ,EGL\_NO\_SURFACE ,EGL\_NO\_SURFACE , EGL\_NO\_CONTEXT);  
&nbsp;&nbsp;&nbsp;eglDestroySurface(m\_eglDisplay,m\_eglSurface);  
&nbsp;&nbsp;&nbsp;m\_eglSurface = EGL\_NO\_SURFACE;  
&nbsp;&nbsp;}  
&nbsp;}

  

&nbsp;void ResetSurface(void)  
&nbsp;{  
&nbsp;&nbsp;if(m\_eglSurface == EGL\_NO\_SURFACE)  
&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;m\_eglSurface = eglCreateWindowSurface(m\_eglDisplay,m\_eglConfig , m\_nativeWindowType , NULL);  
&nbsp;&nbsp;&nbsp;eglMakeCurrent(m\_eglDisplay ,m\_eglSurface ,m\_eglSurface , m\_eglContext);  
&nbsp;&nbsp;}  
&nbsp;}
