 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Krice Guest
|
Posted: Sat Jul 30, 2005 7:05 pm Post subject: Second class instance fails |
|
|
If I make two instances of the class, the second one will fail:
map_tiles=new G_Tile("terrain.wst",32,32,3,0);
back_tiles=new G_Tile("backtiles.wst",32,32,2,1);
The program doesn't crash and the code seems to work, but the tiles
are not showing for the second instance. If I switch places then
back_tiles can be seen, but not map_tiles. Then I discovered that
if I put some code between those calls, then both will work. In
this case:
map_tiles=new G_Tile("terrain.wst",32,32,3,0);
ustr=new Font(8,16,"bfonts.bmp");
back_tiles=new G_Tile("backtiles.wst",32,32,2,1);
What could be the reason for that?
|
|
| Back to top |
|
 |
red floyd Guest
|
Posted: Sat Jul 30, 2005 7:38 pm Post subject: Re: Second class instance fails |
|
|
Krice wrote:
| Quote: | If I make two instances of the class, the second one will fail:
map_tiles=new G_Tile("terrain.wst",32,32,3,0);
back_tiles=new G_Tile("backtiles.wst",32,32,2,1);
The program doesn't crash and the code seems to work, but the tiles
are not showing for the second instance. If I switch places then
back_tiles can be seen, but not map_tiles. Then I discovered that
if I put some code between those calls, then both will work. In
this case:
map_tiles=new G_Tile("terrain.wst",32,32,3,0);
ustr=new Font(8,16,"bfonts.bmp");
back_tiles=new G_Tile("backtiles.wst",32,32,2,1);
What could be the reason for that?
|
You have an error on line 42 of your code.
|
|
| Back to top |
|
 |
Krice Guest
|
Posted: Sun Jul 31, 2005 3:28 pm Post subject: Re: Second class instance fails |
|
|
red floyd wrote:
| Quote: | You have an error on line 42 of your code.
|
You must be proud of yourself now.. My guess is that something
inside the constructor corrupts memory, since those objects are
most likely generated one after another in the memory space. But
some of the source code was taken from previous project and that
didn't had any errors. It's these silent memory errors I hate
the most, because they don't even crash the program.
|
|
| Back to top |
|
 |
Krice Guest
|
Posted: Sun Jul 31, 2005 6:48 pm Post subject: Re: Second class instance fails |
|
|
Krice wrote:
| Quote: | My guess is that something inside the constructor corrupts memory
|
First I took SDL_Surface out from the class, but that didn't help.
Only when I removed all SDL variables from the class (as member
variables) the problem was gone. But why SDL doesn't work in a class?
|
|
| Back to top |
|
 |
Krice Guest
|
Posted: Wed Aug 03, 2005 11:28 am Post subject: Re: Second class instance fails |
|
|
Krice wrote:
| Quote: | But why SDL doesn't work in a class?
|
Speaking to myself, but the reason was a local variable with same
name that silently shadowed the class member variable, causing
such unpredictable behavior.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|