Bitmap loads then goes NULL after x iterations
Travis Peterson

Loading bitmap with
ALLEGRO_BITMAP *textBox;
textBox = al_load_bitmap("textbox.png");

and it loads then after about 100 seconds it breaks saying abort() and clicking retry break in VS shows the error is thr textBox pointer is 0x0000000.. NULL

What could cause this?

Chris Katko

Is the working directory correct? Are you reusing the same pointer over-and-over and letting the previous ones crash/leak memory?

and it loads then after about 100 seconds it breaks saying abort()

What exactly loads? Your whole program? Where's the abort coming from?

Edgar Reynaldo

You're probably leaking memory. Are you loading the same bitmap every frame without freeing it?

GullRaDriel

I go with Edgar on that one, I think you are endlessly loading the bitmap.
You should only load it once.
Show us some code.

Travis Peterson

Appreciate your hasty replies, at the beginning of program all the bitmaps and fonts, etc are declared in class headers and defined in their constructors, never once is an allegro bitmap freed/deleted, at end of program seemigly all objects are deleted and vectors cleared.
al_load_bitmap is called each time an object of class textdisplay is created. Directory is set up correct it loads and even displays textBox then gives error sometimes when there should be no textbox displayed

GullRaDriel

In that case, and if your program logic isn't broken, you may have a video memory limit problem.

AFAIK there had to be caveats with C++ constructor and allegro. I don't know if it's still the case with A5.

Anyway, we're not getting further without a minimal portion of code reproducing your problem. I only say that because I recently broke my crystal ball.

Chris Katko

You can't use an Allegro function before initializing Allegro, and if you have any global classes with constructors, or classes created before init'ing Allegro, that's a crash.

Edgar Reynaldo

al_load_bitmap is called each time an object of class textdisplay is created.

If you're doing this more than once, that's a memory leak.

Travis Peterson

al_load_bitmap called in constructor is bad? Would it be better to load them all once in a resources class and assign the bitmap of class textdisplay to the resource bitmap?
Also how could undeallocated memory cause this, all the bitmaps are failing the way textbox did now

Edgar Reynaldo

What I'm saying is, you should only load resources once. If you want to do it in a constructor fine, but be aware that global objects are created before allegro is initialized.

Post more code. main, or a zip file, or whatever.

Travis Peterson

Your suggestion worked edgar, moved all the bitmaps initialization to a resource class and loaded them all once, then assigned the other class bitmap pointers to resources and it workes 100% appreciate the help

Thread #617156. Printed from Allegro.cc