C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Second class instance fails

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Krice
Guest





PostPosted: Sat Jul 30, 2005 7:05 pm    Post subject: Second class instance fails Reply with 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?

Back to top
red floyd
Guest





PostPosted: Sat Jul 30, 2005 7:38 pm    Post subject: Re: Second class instance fails Reply with quote



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





PostPosted: Sun Jul 31, 2005 3:28 pm    Post subject: Re: Second class instance fails Reply with quote



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





PostPosted: Sun Jul 31, 2005 6:48 pm    Post subject: Re: Second class instance fails Reply with quote

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





PostPosted: Wed Aug 03, 2005 11:28 am    Post subject: Re: Second class instance fails Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.