Author Topic: Stack Overflow Error Stacking Frustration  (Read 391 times)

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Stack Overflow Error Stacking Frustration
« on: August 26, 2012, 03:29:56 am »


               Again, at wits end. This involves a previously mentioned pair of scripts that I've been working on. I tied ACP's weapon styles into feats that the player can activate at will, each style granting different bonuses and disadvantages. The code works like a charm, that is, when there are no other effects from anything else applied to the character when they try and change styles.

Here is the include with the functions:
"nc_wep_mstrcntrl"
//Resets to original phenotype
void ResetOriginalPhenoType(object oPC);
void ResetOriginalPhenoType(object oPC)
{

    //If we are at phenotype 50-60 we want to reset it to neutral.
    if (GetLocalInt(oPC, "iOriginalPhenoType") == 0)
    {
        SetPhenoType(0, oPC);
        SendMessageToPC(oPC, "You are now using the Basic Form.");
    }
    //If we are at phenotype 61 - 71 we reset it to neutral.
    else if (GetLocalInt(oPC, "iOriginalPhenoType") == 2)
    {
        SetPhenoType(2, oPC);
        SendMessageToPC(oPC, "You are now using the Basic Form.");
    }
}

void SetWeaponStyle(int iStyle);
void SetWeaponStyle(int iStyle)
{
    if (GetPhenoType(OBJECT_SELF) == iStyle)
    SendMessageToPC(OBJECT_SELF, "You're already using this fighting style!");
    else SetPhenoType(iStyle);
}

//Library of Weapon Style Effects

//Defender Weapon Style Effect, 3/+20 DR, 2% chance to miss
void EffectDefenderStyle();
void EffectDefenderStyle()
    {
    object oPC = OBJECT_SELF;
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectMissChance(5, MISS_CHANCE_TYPE_NORMAL), oPC); //2% Miss Chance
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageReduction(5, DAMAGE_POWER_PLUS_TWENTY), oPC); //Defender Damage Reduction, 5/+20
    }

//Fencer Weapon Style Effect, +1d4 Piercing Damage, +2 Dodge Bonus, -5 Discipline
void EffectFencerStyle();
void EffectFencerStyle()
    {
    object oPC = OBJECT_SELF;
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectACIncrease(2, AC_DODGE_BONUS), oPC); //Fencer AC increase
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d4(1), DAMAGE_TYPE_PIERCING), oPC); //+1d4 Piercing Damage
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectSkillDecrease(SKILL_DISCIPLINE, 5), oPC); //-5 Discipline Penalty
    }

//Powerful Swings Style Effect, +1d6 Bludgeoning Damage, -2 Tumble, -1 Dodge AC
void EffectPowerfulStyle();
void EffectPowerfulStyle()
    {
    object oPC = OBJECT_SELF;
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectACDecrease(1, AC_DODGE_BONUS), oPC); //AC Decrease
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d6(1), DAMAGE_TYPE_BLUDGEONING), oPC); //+1d6 bludgeoning bonus
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectSkillDecrease(SKILL_TUMBLE, 2), oPC); //-2 Tumble
    }

//Twin Blades Style Effect, +2 to off-hand attack bonus, -3 AC
void EffectTwinBladesStyle();
void EffectTwinBladesStyle()
    {
    object oPC = OBJECT_SELF;
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectACDecrease(3, AC_DODGE_BONUS), oPC);
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectAttackIncrease(2, ATTACK_BONUS_OFFHAND), oPC);
    }

//Sun Fist unarmed style, +1d4 Bludgeoning
void EffectSunFistStyle();
void EffectSunFistStyle()
    {
    object oPC = OBJECT_SELF;
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d4(1), DAMAGE_TYPE_BLUDGEONING), oPC); //+1d4 Bludgeoning bonus
    }

//Tiger Fang unarmed style, +1d6 slashing
void EffectTigerFangStyle();
void EffectTigerFangStyle()
    {
    object oPC = OBJECT_SELF;
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d6(1), DAMAGE_TYPE_SLASHING), oPC); //+1d6 slashing bonus
    }

//Dragon Palm unarmed style, +1d6 magical bonus (aka chi)
void EffectDragonPalmStyle();
void EffectDragonPalmStyle()
    {
    object oPC = OBJECT_SELF;
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d6(1), DAMAGE_TYPE_MAGICAL), oPC); //+1d6 magical "chi" bonus
    }

//Ken-Seijin style, +2 Attack Bonus, +1d8 Slashing Bonus
void EffectKenSeijinStyle();
void EffectKenSeijinStyle()
    {
    object oPC = OBJECT_SELF;
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d8(1), DAMAGE_TYPE_SLASHING), oPC); //+1d8 slashing damange bonus
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectAttackIncrease(2, ATTACK_BONUS_MISC), oPC); //+2 Attack Bonus
    }

//Singing Sword style, +2 Attack Bonus, +1d6 Magical Bonus
void EffectSingingSwordStyle();
void EffectSingingSwordStyle()
    {
    object oPC = OBJECT_SELF;
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d6(1), DAMAGE_TYPE_MAGICAL), oPC); //+1d6 Magical Bonus
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectAttackIncrease(2, ATTACK_BONUS_MISC), oPC); //+2 Attack Bonus
    }

//Ars Magna style, +3 Dodge Bonus, +1 Attack Bonus
void EffectArsMagnaStyle();
void EffectArsMagnaStyle()
    {
    object oPC = OBJECT_SELF;
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectAttackIncrease(1, ATTACK_BONUS_MISC), oPC); //Attack Bonus
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectACIncrease(3, AC_DODGE_BONUS), oPC); //AC Bonus
    }

//Bear Claw style, +1d6 Magical Bonus, +1d6 Slashing Bonus
void EffectBearClawStyle();
void EffectBearClawStyle()
    {
    object oPC = OBJECT_SELF;
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d6(1), DAMAGE_TYPE_MAGICAL), oPC); //+1d6 Magical Bonus
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d6(1), DAMAGE_TYPE_SLASHING), oPC); //+1d6 Slashing Bonus
    }

//Lagora-cû style, +1 Attack Per Round, 5% Chance of Missing
void EffectBow1Style();
void EffectBow1Style()
    {
    object oPC = OBJECT_SELF;
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectModifyAttacks(1), oPC);                       //Extra Attack bonus
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectMissChance(5, MISS_CHANCE_TYPE_NORMAL), oPC); //Miss Chance application
    }

//Delos-cû style, +2 Attack Bonus, +1 Dodge Bonus
void EffectBow2Style();
void EffectBow2Style()
    {
    object oPC = OBJECT_SELF;
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectAttackIncrease(2, ATTACK_BONUS_MISC), oPC); //+2 Attack Bonus
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectACIncrease(1, AC_DODGE_BONUS), oPC); //+1 Dodge Bonus
    }

// Removes any previous weapon style effects that may be on the player so
// they can't stack 'em up and knock 'em down
// Removes any previous weapon style effects that may be on the player so
// they can't stack 'em up and knock 'em down
void RemoveStyleEffects()
{
        object oPC = OBJECT_SELF;
        effect eEffect = GetFirstEffect(oPC);
        while (GetIsEffectValid(eEffect))
        {
         switch (GetEffectSpellId(eEffect))
         {
            case 2307: // Defender Style
            case 2308: // Fencer Style
            case 2309: // Powerful Swings Style
            case 2310: // Twin Blades Style
            case 2311: // Sun Fist Style
            case 2312: // Tiger Fang Style
            case 2313: // Dragon Palm Style
            case 2314: // Ken-Seijin Style
            case 2315: // Singing Sword Style
            case 2316: // Ars Magna Style
            case 2317: // Bear Claw Style
            case 2318: // Lagora-cû style
            case 2319: // Delos-cû style
                RemoveEffect(oPC, eEffect);
                break;
         }
        eEffect = GetNextEffect(oPC);
        }
}[/code]

And here's the script that performs the actual switching. All of the feats are tied to this script.
"nc_wep_styswitch"
#include "nc_wep_mstrcntrl"

void main()
{
//Declare Major Variables
int nStyle = GetSpellId(); //Gets the weapon style that called this script
object oPC = OBJECT_SELF; //Defines the Player Character
int iOrigPheno = GetLocalInt(oPC, "iOriginalPhenoType");//Gets the original phenotype from the variable set on the player OnClientEnter (first entering the game)

switch (nStyle)
{
//Basic Form style (aka default mode)
case 2306:
RemoveStyleEffects();
ResetOriginalPhenoType(oPC);
break;
//Defender style
case 2307:
 switch (iOrigPheno) //Check for the phenotypes
 {
 //Thin phenotype
 case 0:
 RemoveStyleEffects();
 SetWeaponStyle(56);
 EffectDefenderStyle();
 SendMessageToPC(oPC, "You are now using the Defender combat style");
 break;
 //Large Phenotype
 case 2:
 RemoveStyleEffects();
 SetWeaponStyle(67);
 EffectDefenderStyle();
 SendMessageToPC(oPC, "You are now using the Defender combat style");
 break;
 }
break;
//Fencer style
case 2308:
 switch (iOrigPheno) //Check for the phenotypes
 {
 //Thin phenotype
 case 0:
 RemoveStyleEffects();
 SetWeaponStyle(53);
 EffectFencerStyle();
 SendMessageToPC(oPC, "You are now using the Fencer combat style.");
 break;
 //Large Phenotype
 case 2:
 RemoveStyleEffects();
 SetWeaponStyle(64);
 EffectFencerStyle();
 SendMessageToPC(oPC, "You are now using the Fencer combat style.");
 break;
 }
break;
//Powerful Swings style
case 2309:
 switch (iOrigPheno) //Check for the phenotypes
 {
 //Thin phenotype
 case 0:
 RemoveStyleEffects();
 SetWeaponStyle(52);
 EffectPowerfulStyle();
 SendMessageToPC(oPC, "You are now using the Powerful Swings combat style.");
 break;
 //Large Phenotype
 case 2:
 RemoveStyleEffects();
 SetWeaponStyle(63);
 EffectPowerfulStyle();
 SendMessageToPC(oPC, "You are now using the Powerful Swings combat style.");
 break;
 }
break;
//Twin Blades style
case 2310:
 switch (iOrigPheno) //Check for the phenotypes
 {
 //Thin phenotype
 case 0:
 RemoveStyleEffects();
 SetWeaponStyle(51);
 EffectTwinBladesStyle();
 SendMessageToPC(oPC, "You are now using the Twin Blades combat style.");
 break;
 //Large Phenotype
 case 2:
 RemoveStyleEffects();
 SetWeaponStyle(62);
 EffectTwinBladesStyle();
 SendMessageToPC(oPC, "You are now using the Twin Blades combat style.");
 break;
 }
break;
//Sun Fist style
case 2311:
 switch (iOrigPheno) //Check for the phenotypes
 {
 //Thin phenotype
 case 0:
 RemoveStyleEffects();
 SetWeaponStyle(58);
 EffectSunFistStyle();
 SendMessageToPC(oPC, "You are now using the Sun Fist unarmed style.");
 break;
 //Large Phenotype
 case 2:
 RemoveStyleEffects();
 SetWeaponStyle(69);
 EffectSunFistStyle();
 SendMessageToPC(oPC, "You are now using the Sun Fist unarmed style.");
 break;
 }
break;
//Tiger Fang style
case 2312:
 switch (iOrigPheno) //Check for the phenotypes
 {
 //Thin phenotype
 case 0:
 RemoveStyleEffects();
 SetWeaponStyle(57);
 EffectTigerFangStyle();
 SendMessageToPC(oPC, "You are now using the Tiger Fang unarmed style.");
 break;
 //Large Phenotype
 case 2:
 RemoveStyleEffects();
 SetWeaponStyle(68);
 EffectTigerFangStyle();
 SendMessageToPC(oPC, "You are now using the Tiger Fang unarmed style.");
 break;
 }
break;
//Dragon Palm style
case 2313:
 switch (iOrigPheno) //Check for the phenotypes
 {
 //Thin phenotype
 case 0:
 RemoveStyleEffects();
 SetWeaponStyle(59);
 EffectDragonPalmStyle();
 SendMessageToPC(oPC, "You are now using the Dragon Palm unarmed style.");
 break;
 //Large Phenotype
 case 2:
 RemoveStyleEffects();
 SetWeaponStyle(70);
 EffectDragonPalmStyle();
 SendMessageToPC(oPC, "You are now using the Dragon Palm unarmed style.");
 break;
 }
break;
//Ken-Seijin style
case 2314:
 switch (iOrigPheno) //Check for the phenotypes
 {
 //Thin phenotype
 case 0:
 RemoveStyleEffects();
 SetWeaponStyle(50);
 EffectKenSeijinStyle();
 SendMessageToPC(oPC, "You are now using the Ken-Seijin combat style.");
 break;
 //Large Phenotype
 case 2:
 RemoveStyleEffects();
 SetWeaponStyle(61);
 EffectKenSeijinStyle();
 SendMessageToPC(oPC, "You are now using the Ken-Seijin combat style.");
 break;
 }
break;
//Singing Sword style
case 2315:
 switch (iOrigPheno) //Check for the phenotypes
 {
 //Thin phenotype
 case 0:
 RemoveStyleEffects();
 SetWeaponStyle(55);
 EffectSingingSwordStyle();
 SendMessageToPC(oPC, "You are now using the Singing Sword combat style.");
 break;
 //Large Phenotype
 case 2:
 RemoveStyleEffects();
 SetWeaponStyle(66);
 EffectSingingSwordStyle();
 SendMessageToPC(oPC, "You are now using the Singing Sword combat style.");
 break;
 }
break;
//Ars Magna style
case 2316:
 switch (iOrigPheno) //Check for the phenotypes
 {
 //Thin phenotype
 case 0:
 RemoveStyleEffects();
 SetWeaponStyle(54);
 EffectArsMagnaStyle();
 SendMessageToPC(oPC, "You are now using the Ars Magna combat style.");
 break;
 //Large Phenotype
 case 2:
 RemoveStyleEffects();
 SetWeaponStyle(65);
 EffectArsMagnaStyle();
 SendMessageToPC(oPC, "You are now using the Ars Magna combat style.");
 break;
 }
break;
//Bear Claw style
case 2317:
 switch (iOrigPheno) //Check for the phenotypes
 {
 //Thin phenotype
 case 0:
 RemoveStyleEffects();
 SetWeaponStyle(60);
 EffectBearClawStyle();
 SendMessageToPC(oPC, "You are now using the Bear's Claw unarmed style.");
 break;
 //Large Phenotype
 case 2:
 RemoveStyleEffects();
 SetWeaponStyle(71);
 EffectBearClawStyle();
 SendMessageToPC(oPC, "You are now using the Bear's Claw unarmed style.");
 break;
 }
break;
//Langora-cû Style
case 2318:
 switch (iOrigPheno) //Check for the phenotypes
 {
 //Thin phenotype
 case 0:
 RemoveStyleEffects();
 SetWeaponStyle(51);
 EffectBow2Style();
 SendMessageToPC(oPC, "You are now using the Langora-cû ranged style.");
 break;
 //Large Phenotype
 case 2:
 RemoveStyleEffects();
 SetWeaponStyle(62);
 EffectBow2Style();
 SendMessageToPC(oPC, "You are now using the Langora-cû ranged style.");
 break;
 }
//Delos-cû Style
case 2319:
 switch(iOrigPheno)
 {
 //Thin phenotype
 case 0:
 RemoveStyleEffects();
 SetWeaponStyle(51);
 EffectBow2Style();
 SendMessageToPC(oPC, "You are now using the Delos-cû ranged style.");
 break;
 //Large phenotype
 case 2:
 RemoveStyleEffects();
 SetWeaponStyle(62);
 EffectBow2Style();
 SendMessageToPC(oPC, "You are now using the Delos-cû ranged style.");
 break;
 }
}
}

Currently, everytime you switch, the script checks to see if one of the associated spellid's is active on the player then wipe's the style's effects from them before applying the new ones. This prevents players from stacking effects. Unfortunately, if I try to switch a style while something like Mage Armor is active, it causes a stack overflow and nothing happens. I'm at wits end here, I have no experience with these kinds of errors.  Please help!

-NineCoronas
               
               

               
            

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Stack Overflow Error Stacking Frustration
« Reply #1 on: August 26, 2012, 06:23:44 am »


               A friend of mine was completely unable to duplicate the issue, despite using the same hak, module, and even character I did.

Here is a screenshot of what happens to me:
'Image

If anyone would be willing to test the module for me to see if they could replicate the error themselves, so I can determine if it's an issue with my PC or something else, I would greatly appreciate it.

Cheers!

-NineCoronas
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Stack Overflow Error Stacking Frustration
« Reply #2 on: August 26, 2012, 01:34:27 pm »


               It is not Your PC.    

I ran into the problem only one time. Recently when I tryed to recreate the error, I could not.  

So my original thinking as to the cause could be flawed.  

In my case, When I had the problem, I was thinking that it was a compiler bug, with how with a var being missed being taken off the stack,  

Since You do not define any Vars in your Case statments I dout that was the problem even when I had it happen to me once.  

Is your friend using the same compiler as you are ?

I am really unsure as to the cause of the problem.  

My current guess, is that it my be caused by a white space character in the script. ( Tab/control-charcters.ect..)

It will be awhile before I get a chance to take a closer look at it. but you can always send it to me for when I get a chance.
               
               

               
            

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Stack Overflow Error Stacking Frustration
« Reply #3 on: August 26, 2012, 05:03:09 pm »


               It's been fixed.
Squatting Monk rewrote the script for me after we went through hours of debugging to no avail; apparently, this nested switch inside of this loop was what caused it.
I'm not sure what compiler he uses, or what a white space character is heh.
Good to know it's not my PC though.
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Stack Overflow Error Stacking Frustration
« Reply #4 on: August 26, 2012, 09:31:21 pm »


               I use the PRC compiler packaged with NWNTX. I'm pretty sure I tried to recreate the bug with the module as NC sent it, before I ever modified any scripts, but I'll check when I get home just to be sure.

The function that was causing it was apparently RemoveStyleEffects(). We rewrote it to remove the switch in the while loop, and it works now.

NC: whitespace == spaces, tabs, or newlines.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Stack Overflow Error Stacking Frustration
« Reply #5 on: August 26, 2012, 10:08:38 pm »


               The one Time I had the error, I was also using a break in a while loop, though it was not in a switch/case statement. That may be the cause when using the default compiler. Still I Am not sure, When I fixed it, the time I had it, I was just as baffeled after the cure. as I was before the cure, as to the cause of the problem.
               
               

               


                     Modifié par Lightfoot8, 26 août 2012 - 09:09 .