Second class instance fails



 DEVELOP > c-Plus-Plus > Second class instance fails

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Krice"
Date: 30 Jul 2005 02:05:06 PM
Object: 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?
.

User: "red floyd"

Title: Re: Second class instance fails 30 Jul 2005 02:38:38 PM
Krice wrote:

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.
.
User: "Krice"

Title: Re: Second class instance fails 31 Jul 2005 10:28:56 AM
red floyd wrote:

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.
.
User: "Krice"

Title: Re: Second class instance fails 31 Jul 2005 01:48:21 PM
Krice wrote:

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?
.
User: "Krice"

Title: Re: Second class instance fails 03 Aug 2005 06:28:00 AM
Krice wrote:

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.
.





  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER