|
Problems with BITMAP*s |
Miles Lombardi
Member #5,876
May 2005
|
My code uses a class that I made called SPRITE. Now SPRITE contains an array of BITMAP*s, the problem is that the first time I come to try and blit one of those BITMAP*s the whole programme crashes. This is the header and constructor for the SPRITE class:
This is the init() function, which is the first one called within main():
Now I cannot see any way that a BITMAP* could go astray and create a pointer error, unless it happens in one of those constructors (which I don't think it does, but if you want to see them you can). link.spr_link_right_walk.draw(105 + 0, 40, 0, 255, 1); This calls the draw function in the SPRITE class, which simply draws a translucent copy of that frame. I don't know what could be going wrong, so could someone please help me? I've been stuck on this bug for a while, and it completely stops the programme . |
GullRaDriel
Member #3,861
September 2003
|
i hear somewhere the story of the Fucking Manual and the Evil 'I contain bitmap and contruct them before allegro is loaded' Class. Maybe you should search more on my story. I'm sorry but i use C, so i do not have the problem you got. "Code is like shit - it only smells if it is not yours" |
ReyBrujo
Moderator
January 2001
|
Are you compiling with gcc? Try to debug that, it should give you the answer. -- |
Miles Lombardi
Member #5,876
May 2005
|
Gull, although that is most likely to be the problem all of the constructors are called after allegro_init(), only the declarations of the classes are called before allegro_init(), and that does not involve any creation of BITMAPs, i think. |
A J
Member #3,025
December 2002
|
if your program crashes, and you dont know how to find the bug, you need to learn how to use a debugger. ___________________________ |
Miles Lombardi
Member #5,876
May 2005
|
Yes I do, Dev-C++s tells me where it goes wrong, but I don't know how to do anything else. |
Evert
Member #794
November 2000
|
Quote: all of the constructors are called after allegro_init() It is my understanding that constructors are called when the variable is declared. Your variables look to be declared before allegro_init(). But even if you do declare them below allegro_init(), I'm not sure if it is guarenteed that the constructors are called after it (it might be though). As a rule of thumb, don't call Allegro functions from inside a constructor function. There are cases where you can do this, but when in doubt, don't do it. |
Miles Lombardi
Member #5,876
May 2005
|
Well there are actually two constructors for all of those things, and when they are declared globally, and pre allegro_init() it doesn't run any allegro functions because it's just a blank constructor. |
ReyBrujo
Moderator
January 2001
|
What does Draw do? Are you sure you are not running out of memory when allocating bitmaps? Can you attach the code? Or debug it to see inside the Draw function to see exactly in which line it crashes, and not only the function. -- |
Miles Lombardi
Member #5,876
May 2005
|
I know exactly where it crashes, on the draw_trans_sprite. |
ReyBrujo
Moderator
January 2001
|
But can you examine if the pointer is NULL, if the trans table is broken in some way, etc? -- |
Miles Lombardi
Member #5,876
May 2005
|
... (top of main.cpp if you need it)
Edit: OBJ_LINK::OBJ_LINK(){ vary = varx = direction = mode = frame = speed = key_length_up = key_length_down = key_length_right = alarm[0] = attacked = 0; } As opposed to:
Is it still running the sprite constructors? |
|