Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Stack overflow help needed


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 ankhd   Members   -  Reputation: 1364

Like
0Likes
Like

Posted 05 March 2014 - 05:54 AM

Hello all.

 

Im getting a stack over flow in this line of code or I think it is.

DWORD GetOwnerPlayerID(void)

{

        (OwnerObj == NULL)

                return -1;

       return OwnerObj->GetOwnerPlayerID();

}//no owner

 

if ownerobj is the same object would this be the cause, I think it is

but the codes been running for month and tonight it crashed on that line

I cant believe I did that hehe. and its been running since  29.1.13 is when I created the class lol

 

 



Sponsor:

#2 Ashaman73   Crossbones+   -  Reputation: 8001

Like
3Likes
Like

Posted 05 March 2014 - 06:06 AM

More info would be helpful. If OwnerObj is a member of the same class which implements GetOwnerPlayerID, then try this (simple cycle detection):

DWORD GetOwnerPlayerID(void)

{

 if (OwnerObj == NULL)

                return -1;


       if (OwnerObj == this) {
   printf("ERROR: cycle detected for object %s !", OwnerObj->getName());
}


       return OwnerObj->GetOwnerPlayerID();

}//no owner


Thought there could be non trivial cycles: A->B->C->A...


Edited by Ashaman73, 05 March 2014 - 07:01 AM.


#3 Vortez   Crossbones+   -  Reputation: 2704

Like
3Likes
Like

Posted 05 March 2014 - 06:44 AM

Why is this function recursive? What does it do, how is it called? we need more information than than. Obliously, the code is right, most probably, just just got stuck in calling that function in an infinite loop until it crashed, but without the rest of the relevent code we can't say much.


Edited by Vortez, 05 March 2014 - 06:46 AM.


#4 Waterlimon   Crossbones+   -  Reputation: 2642

Like
1Likes
Like

Posted 05 March 2014 - 07:06 AM

Apparently DWORD is unsigned, which would mean your return -1; ends up as some huge integer value.

Not sure if that is the problem though, but could be.


o3o


#5 eppo   Crossbones+   -  Reputation: 2624

Like
4Likes
Like

Posted 05 March 2014 - 10:00 AM

How deep is this ownership hierarchy? Perhaps the function isn't optimized for tail recursion and you overflow the stack.

 

Not sure exactly what you're trying to do, but you could probably rewrite it without using recursion:

Object* root = this;

while(root->OwnerObj) root = root->OwnerObj;

return(root->ID);


#6 aregee   Members   -  Reputation: 1026

Like
1Likes
Like

Posted 05 March 2014 - 03:12 PM

More info would be helpful. If OwnerObj is a member of the same class which implements GetOwnerPlayerID, then try this (simple cycle detection):

DWORD GetOwnerPlayerID(void)

{

 if (OwnerObj == NULL)

                return -1;


       if (OwnerObj == this) {
   printf("ERROR: cycle detected for object %s !", OwnerObj->getName());
}


       return OwnerObj->GetOwnerPlayerID();

}//no owner


Thought there could be non trivial cycles: A->B->C->A...

 

You can also do non-trivial cycle check by having two pointers that you trace:

 

You have Pointer A and Pointer B.  For each step, advance Pointer A once, advance Pointer B twice.

 

If the advances are under same conditions, they will meet sooner or later if there is a cycle.  Of course a bit more involving than the method Ashaman73 proposed, but may be a desperate last resort.

 

Using Ashaman73's example:

A->B->C->A

 

Step 1: Pointer A = A, Pointer B = B

Step 2: Pointer A = B, Pointer B = A

Step 3: Pointer A = C, Pointer B = C = Yes, there is a cycle.



#7 ankhd   Members   -  Reputation: 1364

Like
0Likes
Like

Posted 05 March 2014 - 04:54 PM

this object is my explosion object and it has no owner I set it to the explosion object it self  by mistake.

 

Im going to put        if (OwnerObj == this) { printf("ERROR: cycle detected for object %s !", OwnerObj->getName());  in. turns out to be the case

 

one of the projectiles must of polled all cell objects and at the time it picked the explosion object to see if it was a enermy object and called it self over and over.

 

Im going to remove the explosion objects ID I'll return -1;

 

DWORD = -1; = max amount a DWORD can hold I do a bound check on the returned value like this

DWORD error = -1;

if(ID == error)

   do error code; is this not a good Idea the ID will never get to this amount I only need about 8000 IDs thats 8000 units running around 1000 per player

 

I can't believe that it only buged out now after all this time thats been in the code and I ran it many times shooting and all.

 

Im just lucky VC pointed to the code that overflowed.

 

 

the code is like this

cExplosion *explosion = GetFreeExplosionObj();// this is a pool of explosion object pre allocated

 

if(explosion == NULL)

         return false;//error none free

 

 

//see if we can get some particles

 

//add the explotion

UINT error = -1;

UINT CurrentExplosionElement = explosion->GetFreeParticleDataElement();

 

if(CurrentExplosionElement == error)

          return false;//no particles to use maybe next time

 

 

 

 

explosion->InUse = true;//so we dont reuse it

explosion->m_vPos = worldpos;

explosion->OwnerObj = explosion;//bad on my part don't know what I was thinking at the time

 

and when a projectile is fired it checks the cells it travels though for object IDs and if there not allies it explodes and adds a explosion object.

 Thanks everyone for the help.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS