I am writing a program for the Palm OS in c++. I have already posted
this to a palm development forum but I'm desperate for a fix, so I hope
this cross-post isn't offensive.
My program is hanging, like it's in an infinite loop, while returning
from constructing an object. Through the debugger, I've found that it
is hanging on the returning call to the constructor. I put a breakpoint
on the closing bracket of the constructor, and it goes past that point
fine. It hangs on the next step, on the returning line, like this
mg = MyGame();
The variable 'mg' is declared in a file of global variables (as type
MyGame) and referenced through an extern reference.
It appears to work fine the first time the mg object is constructed.
Then I re-use the mg reference when I am resuming a saved game. I don't
have a destructor for the MyGame() object, but I never have. I don't do
any memory allocation within the object.
None of this is new, it's been working fine for months. I haven't made
changes to any of this code. I've made changes to other parts of the
program, but nothing in the MyGame object.
Any ideas? Any help would be greatly appreciated. Thanks. 8 3076
> mg = MyGame();
A temporary is getting assigned. The temporary is destroyed immediately
after the execution of the above statement. Depending on what you have
in your class, this _may_ lead to problems. Why don't you do this
instead...
mg = new MyGame;
Regards,
Srini
Do you have any operator= method in MyGame class check if it is being
called and if it has any locks.
Srini wrote: mg = MyGame();
A temporary is getting assigned. The temporary is destroyed immediately after the execution of the above statement. Depending on what you have in your class, this _may_ lead to problems. Why don't you do this instead...
mg = new MyGame;
Expressions 'MyGame()' and 'new MyGame' have different types. In most
cases if the former compiles, the latter won't.
> Expressions 'MyGame()' and 'new MyGame' have different types. In most cases if the former compiles, the latter won't.
Oh yeah. new returns pointer to the object whereas MyGame() would be a
temporary object. Thanks Victor.
Thanks much for the replies. I found the problem, and it was occurring
else where. I don't know why it appeared to hang coming out of the
constructor. But when I was debugging it again, it got past that
point.
But the replies have me intrigued. Is my code :
mg = myGame();
still incorrect in some way, or have the potential for problems? It
turns out it does work after all, but if there is a better way I'd like
to know.
I tried
mg = new myGame;
and the compiler gave an error of 'illegal operand'.
brifo...@gmail. com wrote: But the replies have me intrigued. Is my code :
mg = myGame();
still incorrect in some way, or have the potential for problems? It turns out it does work after all, but if there is a better way I'd like to know.
Your code will create a new myGame object, by calling the
default constructor. Then, it will assign that object to
'mg' by calling mg's operator= function. Then, the new
object will be destroyed since it is no longer needed.
If you have not written an operator= function for myGame
explicitly, the compiler will generate one for you. But if
myGame has any pointers or other resource handles, then this
compiler-generated operator may not do what you need.
If you post your definition of myGame then we can tell you
if you need to write an operator= function or not.
If you want to avoid this copy operation, you could add a
function to myGame that's designed to clear out an existing
object, eg:
void myGame::clear()
{
member1 = 0;
member2 = "";
// etc.
}
If you feel pretty advanced you could just check the code on another
machine.
But that's a real longshot.
If your code has been truly stable in the past and no changes have been
made in the code where you are seeing the problem:
Try lookin at the assembly language and make some sense out of it.
For example, does the call address for MyGame() actually look
right?
If not, then some corruption occurred.
If so, does it look like the MyGame() code at that address?
The first thing that code of that sort would do, after
calling wrapper functions, is push registers onto stacks. But maybe you
know all of that.
Sometimes libraries are dynamically loaded and
unloaded. That kind of stuff could theoretically become corrupted, but
one would think only inside the OS level.
A true assembly language genious would discover the problem quickly.
As for C++ woof you could try looking for a memory leak. Copy
Constructors are good for that. Somehow your constructor may be
overwriting stack space a bit higher than it. So the return address is
screwed up(on the stack), and thus the address of the line of code will
not actually match what you or your debugger thinks it is. Uh-Oh, a
good debugger would not do this. This is probably all a bad idea.
-Tim This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: JKop |
last post by:
unsigned int CheesePlain(void)
{
unsigned int const chalk = 42;
return chalk;
}
unsigned int& CheeseRef(void)
{
|
by: Siemel Naran |
last post by:
Hi. I have found one advantage of returning values through the argument
list. It's that we have to store the return value. But when we return by
value, we may forgot to store the return value.
Consider,
void f(int x, int& i);
int i, j;
f(1, i);
|
by: Tony Johansson |
last post by:
Hello!!
Assume you have the following AccountForStudent class
class AccountForStudent
{
public:
AccountForStudent ();
AccountForStudent (long, double);
~AccountForStudent ;
|
by: joeted |
last post by:
Hi,
I am using system.diagnostic.process with the intention of running a
program to communicate with a unix box:
The program is "PuTTY", running from a batch script. I know it works
because if i manually trigger the batch, the results can be seen on the
unix side.
Running the batch script from an .aspx page however makes the process
|
by: mohammaditraders |
last post by:
a program which consists of a class named Student, the class should
consists of three data members Name, Ob_marks, Total_marks and two
member functions Cal_percentage() which calculate the percentage of
the student by the formula (Ob_marks * 100 ) / Total_marks and
Display() which show all information of the student. The class should
also contain the default constructor which initializes all the data
member of the class.
In main program...
| |
by: mike3 |
last post by:
Hi.
I seem to have made some progress on finding that bug in my program. I
deactivated everything in the bignum package that was used except for
the returning of BigFloat objects. I even crippled all the
constructors. So now all the operations and constructors that were
used do is just return BigFloats but no memory is actually accessed at
any point, nor is any allocated. However, when I reenable those parts
of the constructor that...
|
by: wshaer |
last post by:
Hi all,
I have an assignment and I need some help with it. This is the assignment
//
Research reports are often required to conform to a given standard such as APA or MLA. These standards specify things like the size of the margins and formats for titles, paragraphs, references, page numbers, etc. Suppose that a program is to produce a report conforming to a standard. It would be desirable to provide utility class to automatically conform...
|
by: Microsoft |
last post by:
Hi
I have a c# program that continually runs 24/7 and performs a variety of
tasks based on a timer.
There is one routine that hangs every Saturday morning without fail. If I
restart the program throughout the week is still hangs. I can restart it
immediatly after the hang and it runs fine until next Saturday.
There is nothing different about Saturday that I can think of.
|
by: JDS |
last post by:
I have an application that interfaces with a USB device using the .Net
serial port. The code works fine, displaying live data on the screen;
that is until the USB lead is pulled out from the PC when the program
hangs.
The obvious answer is not to pull the lead out, but unfortunately the
application is one in which there is a high possibility the lead will
be pulled out so the code needs to be more robust.
The form has a timer...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |