Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Help for al_draw_ustr()

Credits go to Edgar Reynaldo for helping out!
This thread is locked; no one can reply to it. rss feed Print
Help for al_draw_ustr()
Korhal
Member #15,603
May 2014

Hello there,

I am a beginner to allegro 5 and I want to use Allegro 5 in c++ at university to develope a programm that simulates the movement of a machine.

In this programm, the user chooses several sets of parameters for the simulation. Then every set of Parameters is simulated. The Process is shown to the user in a Window on the screen. For every set of parameters a new window is opened and closed after the simulation is finished.

Problem:
When I want to simulate more than 56 sets of parameters the Programm aborts and I get an errormessage:

allegro-5.0.10-monolith-mt.dll! al_draw_ustr() + 0x80 bytes

I don't understand what this means. The error seems to happen in the moment when a new window for a new simulation opens. I see the window but no thing is drawn yet on it. I checked if i destroy all the *font and *display but that seems to be correct.
I hope I was able to describe my problem sufficiently. Please let me know if you need further information.

Thanks a lot for your help!!

AMCerasoli
Member #11,955
May 2010
avatar

I think that crash may be related to a uninitialized pointer. After you destroy the fonts are you loading them again after you start running your next simulation?

Edgar Reynaldo
Member #8,592
May 2007
avatar

Allegro 5 from Git said:

addons/font/text.c#SelectExpand
71/* Function: al_draw_ustr 72 */ 73void al_draw_ustr(const ALLEGRO_FONT *font, 74 ALLEGRO_COLOR color, float x, float y, int flags, 75 const ALLEGRO_USTR *ustr) 76{ 77 ASSERT(font); 78 ASSERT(ustr); 79 80 if (flags & ALLEGRO_ALIGN_CENTRE) { 81 /* Use integer division to avoid introducing a fractional 82 * component to an integer x value. 83 */ 84 x -= font->vtable->text_length(font, ustr) / 2; 85 } 86 else if (flags & ALLEGRO_ALIGN_RIGHT) { 87 x -= font->vtable->text_length(font, ustr); 88 } 89 90 if (flags & ALLEGRO_ALIGN_INTEGER) 91 align_to_integer_pixel(&x, &y); 92 93 font->vtable->render(font, color, ustr, x, y); 94}

In the debug build, a null font or ustr would be caught by the assert. In the release build the only way it could crash is if font is corrupt (ie. already freed). I suppose a corrupt ustr could crash it too though.

Use the debug build and run it through a debugger. It should may segfault if one of the two is corrupt and already freed. It is possible you are using a font that has been destroyed already.

Hope this helps.

Korhal
Member #15,603
May 2014

Thanks a lot for your help!
I tried to reduce the amount of initializing fonts, event_queue and timer.
Might it be a problem that in every loop I us for the simulation I use lines like the following:
font = al_load_font("Orbitron Black.ttf", 20, NULL);

Is this affecting the location where the information is storred?
I just thought that this might lead to the error. Maybe there
is a better way to change the text size???

Up to now I placed the following lines to another position of my program so they don't get executed in every loop:
ALLEGRO_DISPLAY *display;
ALLEGRO_FONT *font = al_load_font("Orbitron Black.ttf", 35, NULL);
ALLEGRO_EVENT_QUEUE *event_queue;
ALLEGRO_TIMER *timer;

But still getting the following error:
Unhandled exception at 0x5528fa60 (allegro-5.0.10-monolith-mt.dll) in Test_mit_VC2010.exe: 0xC0000005: Access violation reading location 0x00000008.

Edgar Reynaldo
Member #8,592
May 2007
avatar

Yeah, you probably have a giant memory leak. You should not be initializing your display, queue, timer, etc on every loop. You want to initialize them once for your window and then destroy them when you are done to prevent a memory leak. Same goes for fonts. If you load them on every iteration without also destroying them then you will be leaking memory, which will eventually cause it to crash when it runs out of memory.

So, make sure you're not doing that, and if you still have problems, try to post code in <code>code goes here...</code> tags.

Korhal
Member #15,603
May 2014

Thank you for your help!
It took quite a lot of effort to correct my program.
There where still other problems but now it works as intended!;D

Thanks a lot for your support!

Go to: