Re: [AD] Not freeing resources of non-preserved bitmaps on Android is considered harmful :) |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: allegro-developers@xxxxxxxxxx
- Subject: Re: [AD] Not freeing resources of non-preserved bitmaps on Android is considered harmful :)
- From: Max Savenkov <max.savenkov@xxxxxxxxxx>
- Date: Fri, 23 Oct 2015 10:05:29 +0300
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type; bh=Pg5/N0JkVfO194F9ETYYOfSwrI+5XTAHGr422W/a3qE=; b=gtdNhA16qya8yZpM/zQ2Iugbg9XHcCOKYCHLG1aKEyMbAt1e9BNo17XjxRGB9XYemb fWLRLlguHT8ZkfgRVrnCJuh1KWlExaSNSyXUItpIpCa1Ekpc3m0S3W+tonwAPUK7hfAv xigSO9mTJRC+qqqJSSBsxN7abklgNq0X7eV08lcRlqTqp1SVsow8IHisB/1pTJXutVTU LK3JiCG1+b6iEPsIwWiv5KjulahbkM//fmh8dJP6JUEDxD6GsSD38HZmgVd0bhfVRSET Ffe6QutsU/VYWdV/TyO4zLBcu3I07Ji8QWMcRPokgUlj0cYtfQ5FkdUbsj7PxFrE7JEN bw4w==
Hm. That might work. My patch moves the burden of recreating the texture
to user, which is probably what he deserves, by using NO_PRESERVE flag,
but it may be less error-prone to re-create the texture inside Allegro.
I've attached a patch that removes NO_PRESERVE checks from both halt and
resume functions, and adds a null pointer check in upload_bitmap_memory.
Not sure about the last one - maybe we should just call
ogl_create_bitmap instead?
Yeah I think I'd prefer calling ogl_create_bitmap rather than add mysterious
behaviour to _al_ogl_upload_bitmap_memory.
Except I missed the fact that we don't want to create a new bitmap, but
rather replace inner 'texture' member in bitmap->extra, so
_al_ogl_create_bitmap won't do. We can, however, copy relevant (small)
part of code from upload_bitmap_memory. Patch attached.
src/android/android_display.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/android/android_display.c b/src/android/android_display.c
index 9f65880..b50d0e9 100644
--- a/src/android/android_display.c
+++ b/src/android/android_display.c
@@ -790,8 +790,7 @@ static void android_acknowledge_drawing_halt(ALLEGRO_DISPLAY *dpy)
int bitmap_flags = al_get_bitmap_flags(bmp);
if (!bmp->parent &&
- !(bitmap_flags & ALLEGRO_MEMORY_BITMAP) &&
- !(bitmap_flags & ALLEGRO_NO_PRESERVE_TEXTURE))
+ !(bitmap_flags & ALLEGRO_MEMORY_BITMAP))
{
ALLEGRO_BITMAP_EXTRA_OPENGL *extra = bmp->extra;
al_remove_opengl_fbo(bmp);
@@ -851,12 +850,21 @@ static void android_acknowledge_drawing_resume(ALLEGRO_DISPLAY *dpy)
int bitmap_flags = al_get_bitmap_flags(bmp);
if (!bmp->parent &&
- !(bitmap_flags & ALLEGRO_MEMORY_BITMAP) &&
- !(bitmap_flags & ALLEGRO_NO_PRESERVE_TEXTURE))
+ !(bitmap_flags & ALLEGRO_MEMORY_BITMAP))
{
int format = al_get_bitmap_format(bmp);
format = _al_pixel_format_is_compressed(format) ? ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE : format;
- _al_ogl_upload_bitmap_memory(bmp, format, bmp->memory);
+ if ( !(bitmap_flags & ALLEGRO_NO_PRESERVE_TEXTURE) ) {
+ _al_ogl_upload_bitmap_memory(bmp, format, bmp->memory);
+ }
+ else {
+ ALLEGRO_BITMAP *tmp = _al_create_bitmap_params(_al_get_bitmap_display(bmp), bmp->w, bmp->h, format,
+ al_get_bitmap_flags(bmp));
+ ((ALLEGRO_BITMAP_EXTRA_OPENGL *)bmp->extra)->texture =
+ ((ALLEGRO_BITMAP_EXTRA_OPENGL *)tmp->extra)->texture;
+ ((ALLEGRO_BITMAP_EXTRA_OPENGL *)tmp->extra)->texture = 0;
+ al_destroy_bitmap(tmp);
+ }
bmp->dirty = false;
}
}