Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Bitmap loads then goes NULL after x iterations

This thread is locked; no one can reply to it. rss feed Print
Bitmap loads then goes NULL after x iterations
Travis Peterson
Member #16,756
October 2017

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
Member #1,881
January 2002
avatar

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?

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Edgar Reynaldo
Member #8,592
May 2007
avatar

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

GullRaDriel
Member #3,861
September 2003
avatar

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.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Travis Peterson
Member #16,756
October 2017

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
Member #3,861
September 2003
avatar

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.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Chris Katko
Member #1,881
January 2002
avatar

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.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Edgar Reynaldo
Member #8,592
May 2007
avatar

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
Member #16,756
October 2017

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
Member #8,592
May 2007
avatar

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
Member #16,756
October 2017

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

Go to: