473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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?

Jul 30 '05 #1
4 1110
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.
Jul 30 '05 #2
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.

Jul 31 '05 #3
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?

Jul 31 '05 #4
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.

Aug 3 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tobiah | last post by:
What is the purpose of the second argument to super()? What is meant by the returning of an 'unbound' object when the argument is omitted. Also, when would I pass an object as the second...
0
by: Brano Zarnovican | last post by:
Hi ! I need to import a module and create an instance of a class from that module (in C). import mod o = mod.klass() (mod.klass is a subclass of tuple)
4
by: Vedanta Barooah | last post by:
greetings.... in a python nested class is it possible to change the value of the parent class's variable without actually creating an instance of the parent class, consider this code: class...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
2
by: info | last post by:
I am pasting in a recordset from access to an excel sheet via VBA successfully. Then my routine copies a range of cells and pastes them into another range, this works fine every other time it...
1
by: Jon Pope | last post by:
I've got an application that uses a Mutex to prevent multiple instances of the application from launching. This works great for me. However, what I would like to do is when a second attempt to...
3
by: RDI | last post by:
Both of the fail messages are dialog boxes that say "An unhandeled exception of type 'System.NullReferenceException' occured in WindowsApplication5.exe "Additional information: Object reference...
7
by: SevDer | last post by:
Hi I have a class library that needs to download the HTML in a specific page of ours with provided querystring. When I open this URL with any browser, it loads fine. When I do WebRequest from Web...
12
by: keepyourstupidspam | last post by:
Hi, I am writing a windows service. The code runs fine when I start the service when my machine is running but it fails to start automatically when the machine reboots. The code bombs out when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.