Limit on Sub Bitmaps?
thebignic

What are the limitations on number/size of sub bitmaps?

Is there any way that sub bitmap creation can fail (ie: not enough memory?) such that it would still return a valid (or valid SEEMING) bitmap address?

Chris Katko

Hmm....

#SelectExpand
1ALLEGRO_BITMAP *al_create_sub_bitmap(ALLEGRO_BITMAP *parent, 2 int x, int y, int w, int h) 3{ 4 ALLEGRO_BITMAP *bitmap; 5 6 if (parent->parent) { 7 x += parent->xofs; 8 y += parent->yofs; 9 parent = parent->parent; 10 } 11 12 bitmap = al_calloc(1, sizeof *bitmap); //<---- zero'd, memory allocation 13 bitmap->vt = parent->vt; 14 15 /* Sub-bitmap inherits these from the parent. 16 * Leave these unchanged so they can be detected if improperly accessed 17 * directly. */ 18 bitmap->_format = 0; 19 bitmap->_flags = 0; 20 bitmap->_display = (ALLEGRO_DISPLAY*)0x1; 21 22 bitmap->w = w; 23 bitmap->h = h; 24 bitmap->locked = false; 25 bitmap->cl = bitmap->ct = 0; 26 bitmap->cr_excl = w; 27 bitmap->cb_excl = h; 28 al_identity_transform(&bitmap->transform); 29 al_identity_transform(&bitmap->inverse_transform); 30 bitmap->inverse_transform_dirty = false; 31 al_identity_transform(&bitmap->proj_transform); 32 al_orthographic_transform(&bitmap->proj_transform, 0, 0, -1.0, w, h, 1.0); 33 bitmap->shader = NULL; 34 bitmap->parent = parent; 35 bitmap->xofs = x; 36 bitmap->yofs = y; 37 bitmap->memory = NULL; 38 39 _al_register_destructor(_al_dtor_list, bitmap, 40 (void (*)(void *))al_destroy_bitmap); 41 42 return bitmap; 43}

I don't see anything in there that would give you a "valid" set of memory (that is, accessible without a segfault) but full of corrupted data... it looks like if it's a bad block of memory, all of those dereferences should explode pretty quickly.

Valgrind might be very helpful if you've got access to a Linux box. If you've got a small sample that can replicate the problem, the Allegro devs are real good about fixing bugs.

Are you tracking your memory usage? (ala Task Manager?) Are you low on memory when it happens?

[edit]

Wait, I'm not familiar with Allegro's internals but:

   if (parent->parent) {
      x += parent->xofs;
      y += parent->yofs;
      parent = parent->parent;
   }

Would this fail to keep the "offsets" correct if there is a sub-sub-bitmap? (or sub-sub-sub-bitmap)?

Bignic, are you using deeply nested sub-bitmaps, or just lots of them?

Thread #616848. Printed from Allegro.cc