Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Allegro 5.1.5 and resizing problems

This thread is locked; no one can reply to it. rss feed Print
Allegro 5.1.5 and resizing problems
kovarex
Member #14,203
April 2012

Hi, I'm just struggling with the upgrade of allegro 5.1.3 -> 5.1.5.
When I run the game, it works until I resize the window.
At that point

a) Fonts are working
b) Primitives are working (gui)
c) Everything else is black, it seems like all bitmaps are lost.

I went through the changelog of 5.1.4 and 5.1.5 and I didn't find any clue, do you have any suggestion?

Edit:
I tried it in debug mode, and checked, that acknowledge resize is still called, but strange thing happened, everything turned to be white instead of black in debug mode :)
I also found out, that newly loaded bitmaps (after the resize) work.

www.factorio.com - a factory building game.

jmasterx
Member #11,410
October 2009

I just upgraded to 5.1.5 to try this out. My game uses a bunch of fonts and dynamic resizing and I'm not seeing any problems. :/

-Try using OpenGL.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

kovarex
Member #14,203
April 2012

I did incorporate the patch (sorry that I didn't mention it in the first post), works the same with or without it.

When I switch to OPENGL it works.

(But I need to use d3d on windows, for obvious (performance) reasons)

Edit: Isn't it strange, that d3d_resize_display was never called when I resized? (only d3d_acknowledge_resize).

www.factorio.com - a factory building game.

jmasterx
Member #11,410
October 2009

Is there any way you could show some pertaining code?

-Init
-Addon init
-Display init
-Major events

kovarex
Member #14,203
April 2012

This is the init of allegro:

#SelectExpand
1 if (global->graphicsSettings->getFullScreen()) 2 al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); 3 else 4 al_set_new_display_flags(ALLEGRO_RESIZABLE); 5 al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST); 6 if (global->graphicsSettings->getMultisamplingLevel() != 0) 7 { 8 al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR | ALLEGRO_VIDEO_BITMAP); 9 al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST); 10 al_set_new_display_option(ALLEGRO_SAMPLES, global->graphicsSettings->getMultisamplingLevel(), ALLEGRO_SUGGEST); 11 } 12 else 13 { 14 al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP); 15 al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 0, ALLEGRO_SUGGEST); 16 al_set_new_display_option(ALLEGRO_SAMPLES, 0, ALLEGRO_SUGGEST); 17 } 18 19 this->display = al_create_display(width, height); 20 21 if (!this->display) 22 throw std::runtime_error("failed to create display!"); 23 if (!al_init_image_addon()) 24 throw std::runtime_error("Failed to initialize al_init_image_addon!"); 25 26 this->temporaryIcon = al_load_bitmap((global->resourcePath / "factorio-icon.png").string().c_str()); 27 if (!this->temporaryIcon) 28 throw std::runtime_error("Failed to load window icon!"); 29 al_set_display_icon(this->display, this->temporaryIcon); 30 31 if (!al_install_keyboard()) 32 throw std::runtime_error("failed to initialize the keyboard!"); 33 if (!al_install_mouse()) 34 throw std::runtime_error("failed to initialize the mouse!"); 35 al_init_font_addon(); 36 if (!al_init_ttf_addon()) 37 throw std::runtime_error("failed to initialize the ttf addon!"); 38 if (!al_init_primitives_addon()) 39 throw std::runtime_error("failed to load primitives addon!"); 40 if (!al_install_audio()) 41 throw std::runtime_error("Failed to install audio!"); 42 if (!al_init_acodec_addon()) 43 throw std::runtime_error("Failed to initialize audio codecs!"); 44 if (!al_reserve_samples(50)) 45 throw std::runtime_error("Failed to reserve samples!"); 46 this->loadAllegroFonts();

This is the part of the atlas bitmap creation (those are the bitmaps that get corrupted)
At this stage:
new bitmap format flags = 2
New bitmap flags = 1024
These values are the same for the 5.1.3 and 5.1.5 version.

 this->atlas = al_create_bitmap(this->width, this->height);
  if (this->atlas == NULL)
    throw std::runtime_error(ssprintf("Couldn't create atlas bitmap (size %uX%u)."
                                      "Probably not enough of video memory.", this->width, this->height));
  al_set_target_bitmap(this->atlas);
  al_clear_to_color(al_map_rgba_f(0, 0, 0, 0));

When I resize the display al_acknowledge_resize->d3d_acknowledge_resize is called (not al_resize_display)

I tried to mimic the change in the peters patch, and added this line to the
d3d_acknowledge_resize function, but it didn't help.

 _al_d3d_prepare_bitmaps_for_reset(disp);

Edit: I did some debugging, _al_d3d_refresh_texture_memory is called, it obviously goes through all my bitmaps and sub-bitmaps

Edit: My fight with the bug continues.
I found out, that even in 5.1.3 I have the same problem, when I stop using the window icon. Yes you heard me right, I stop using window Icon and resizing now starts to mess all my bitmaps.
I found out, that this has something to do with the fact, that I used subitmap of my atlas bitmap for the windows icon, and that the fact, that I used it changed the state of the bitmap.

Properties :lock_x, lock_y, lock_w, lock_h and lock_flags had all value -842150451 when I didn't use the bitmap from the atlas as window icon.
When I use it, it changes these values and the resize works correctly.

So I tried to turn the using of the window icon off and call this function on the atlas after it is filled with images:

al_lock_bitmap(atlas.atlas, al_get_bitmap_format(atlas.atlas), 
ALLEGRO_LOCK_READONLY);

and really strange thing happened, the atlas did survive the resize, but just once!
When I tried to resize again, it was lost again.
So I tried to call this function after every resize, but it didn't help, second resize did kill it.

This is all magic for me now ... computers ... zeros and ones, nobody really can understand it.

Edit: So I investigated more, and went deep into the drawing routine, and found out, what exactly happens there, seems, like calling this on all of my atlas bitmaps saves them from being lost:

// MAGIC, when removed, atlas is lost on resize
al_lock_bitmap(atlas, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY);
al_unlock_bitmap(atlas);

In other words, atlas needs to have lock flags, but can't be locked to make it work.

www.factorio.com - a factory building game.

Go to: