Need Alternative Method(maybe) ? Maximum Call Stack Error

FINAL: Things are working! So... turns out ItemCore doesn't play nice with my(DreamX) auto-equip integrated with my DynamicActors plugin. At least with an initial equipment set. So the solution? Empty out the initial equipment, and just give it to the player via Event in-game. *phew*

Can't believe it took me this long to figure it out, but still... thank you to all those who have been patient with me and working with me. 🙂

UPDATES (in spoiler text) - last updated 06/24/2019 @15:53pm (PST)
Spoiler
Update10: Still unable to determine the "main" culprit behind this, however I am noticing a pattern.... multiple "changeEquip()" aliases seem to be digging themselves into an infinite loop. Example:

LordV_ObjBasedSwVar.js I made it so it overwrote the original method, adding in compatability here and there for YEP_EquipCore, the original function, etc. And then in LordV_DynamicActors, it saves the 'current' item (if any), calls the original (or in this case the overwrote method from LordV_ObjBasedSwVar.js), and continues about its day..... now here comes the fun part... any further plugins that alias changeEquip() after that seem to be called back in this infinite loop.

I guess it's because the later plugins override and if their method is called they call the overrides? I don't know exactly how it works, but it is a problem >:( Everything was working fine until I activated another plugin that overwrites changeEquip() and now I'm having the blackout issue again.

-----
Update9: I think I understand where the loop is coming from.... when the changeEquip() is called from DynamicActors (lowest in plugin order), it makes a call back to the original - or previously alias'd method - which is in ObjBasedSwVar... which then makes a call to the original/previously alias'd method, etc (But DynamicActors overrides it, so I think it calls that one again...

I think that means that THAT is the main problem here. I'm going to try to just flat out override changeEquip (copying the original code in, and adding in a compatability section for YEP_EquipCore) and see if that works.

------
Update8: A minor setback... copying over the 'working' scripts into the main project has brought me back to the equips() problem and a few others as mentioned in previous updates here. So I tried putting some console messages in YEP_EquipCore's equips() function and this is what I got...
9b2NudM.png

Code:
Yanfly.Equip.Game_Actor_equips = Game_Actor.prototype.equips;
Game_Actor.prototype.equips = function() {
    var debug = this.currentClass().equipSlots.length;
    console.log("YEP_EquipCore: equips: length = "+String(debug)); // DEBUG
    for (var i = 0; i < this.currentClass().equipSlots.length; ++i) {
      if (this._equips[i] === undefined || this._equips[i] === null) {
          console.log("equip"+String(i)+" initialized"); // DEBUG
        this._equips[i] = new Game_Item();
      }
    }
    return Yanfly.Equip.Game_Actor_equips.call(this);
};
I even put some console.logs in my changeEquip() function (LordV_ObjBasedSwVar.js) and.... can't even show you the log there, as it seems to loop on forever.

------
Update7: Progress is being made... setting independent items back to all 0, and a change in initEquips to account for YEP_EquipCore compatibility has made things stable.... however, I really want to use YEP_ItemCore's independent items. See Update5's screenshot for the current problem.

------
Update6: Still messing around here, trying to solve this, but I came across something interesting - but annoying. My System.json data is still reading actors 1-4 with their old initial data (when you first start a project).... Even though I have deleted the actors from both the party setup, from the Actors tab itself, reduced maximums to 1 ("our Test subject") and changed up the equips....

------
Update5: When I comment out my initEquips (that scans starting equips for meta tags for the dynamic actors system), it gives THIS error instead:
v9SvBYY.png


------
Update4: Alright so I put the plugins (YEP_CoreEngine, YEP_ItemCore, YEP_EquipCore, LordV_ObjBasedSwVar, and LordV_DynamicActors) in a separate project. After I copied over my resources (characters, faces, etc for the dynamic actors plugin) I loaded it up and everything was fine... however... I had forgotten the notetags. So I put those in, and now the game starts up blank (frozen) and can't open the console menu. So something is locking up somewhere...

------
Update3: Thought the "this._equips[slotId].object()" would've been the item problem with Function.DataManager.isItem, so I changed it back to this.equips()[slotId], then I'm back to the same problem (bunch of changeEquips logged, and at the top YEP_EquipCore = line 467 "Game_Actor.prototype.equips"... UGH!

------
Update2: Welp, got the weird error again (moving ObjBasedSwVar below ItemCore but above EquipCore):
pAWYceY.png


------
Update1: @caethyril Well setting max weapons/armors to 0 -at first- seemed to solve the issue, but the moment (at character creation) I switch (which changes outfits) it cropped up a different error .. which I can't seem to replicate now. I tried changing from
Code:
var oldItem = this.equips()[slotId];
to
Code:
var oldItem = this._equips[slotId].object();
which got rid of the other unexpected error (about registering the item or something from YEP_ItemCore). However, now I still get the changeEquip max call stack error since I've just bypassed equips() is all....


EDIT: The problem was somewhere between the changeEquip(), notetags, or initEquips()... I'm still not 100% sure, but at the moment it's working. When more plugins that change/alias the changeEquip() function are added however... it breaks again.
are those the only 2 plugins you use? or do you have more plugins?
most of the time the "maximum call stack error" is because you need to change the plugin
higher or lower or put the one below the other in order to get it to work.

If neither works, ask the creator of the plugin that did it for you or someone with knowledge.
Just some ideas~

Stack size exceeded almost always means you have a loop, e.g. "update equips -> update items -> update equips -> ... -> stack size exceeded".

Have you modified Equip Core at all, and/or are you using an outdated version? Asking because line 467; 39 of YEP_EquipCore v1.18 (current version) looks like an innocent function declaration. May be a good idea to re-download it just in case, could be corrupted (it happens sometimes). Also check your other plugins are up-to-date if you haven't already.

Item Core's major alteration is independent items. Maybe try setting its Max Items, Max Weapons, and Max Armors plugin parameters all to 0 (removes independent items) to see if that helps? 🙂

And yes, like ShadowDragon says, plugin order is important; you'll probably want to load yours after Yanfly's, and ensure Yanfly's are in the recommended order: http://yanfly.moe/yep/
EDIT: See OP for all updates
________________________
are those the only 2 plugins you use? or do you have more plugins?
most of the time the "maximum call stack error" is because you need to change the plugin
higher or lower or put the one below the other in order to get it to work.

If neither works, ask the creator of the plugin that did it for you or someone with knowledge.

This is the current list of plugins that are "ON" (of which the problems consist of YEP_ItemCore + YEP_EquipCore + my plugins):
- RS_WaveFilter
- OuterSelfSwitch
- Galv_ImageCache
- VE_BasicModule
- VE_CustomVehicles
- YEP_CoreEngine
- YEP_MessageCore
- YEP_SelfSwVar
- YEP_BattleEngineCore
- YEP_BuffsStatesCore
- YEP_ItemCore
- YEP_SkillCore
- YEP_EquipCore
- YEP_StatusMenuCore
- YEP_KeyNameEntry
- YEP_KeyboardConfig
- YEP_TouchInputDisabler
- LordV_ObjBasedSwVar
- LordV_DynamicActors
- LordV_Pirates
- SRD_RemovedTitleScreen

The problem is most definitely within the changeEquip() function and equips(), with how the scripts are handled.

@caethyril I'm certain. I have just downloaded and installed them yesterday directly from Yanfly's plugins list, so they're the newest that I know of, unaltered, and yes my plugins are after Yanfly's (they have to be), since my Obj-Based Switches and variables alias's and overrides YEP_ItemCore's "gainIndependentItem" function.

See what I'm confused about is where in the startup process would "changeEquip" even be called? I have an armor in the body slot of the starting actor, and the autoequip section happens on changeEquip (empty slot = ensure the armor is equipped, yada yada; unequip - delete the excess item). But I don't get why there's a call to changeEquip in the first place. initEquips should've taken care of all of that in the beginning.

So I'll try:
  • Setting independent items to 0
  • putting ObjBasedSwVar after YEP_ItemCore but before YEP_EquipCore?
  • Doing the above but seperate the "gainIndependentItem()" function after all of yanfly's scripts as a patch?
See where we can go from there...
@lordvalinar is ObjBasedSwVar on one of YEP plugin of SelfSwVar? if so, replace it underneath it.
as for SRD, can you turn it off and see if it works corectly?
if it does, replace SRD with YAMI_SkipTitle. as for the other info, i have no idea.
@lordvalinar is ObjBasedSwVar on one of YEP plugin of SelfSwVar? if so, replace it underneath it.
as for SRD, can you turn it off and see if it works corectly?
if it does, replace SRD with YAMI_SkipTitle. as for the other info, i have no idea.

no ObjBasedSwVar is my own plugin. To store switches and variables on nearly any object (actors, party, items, map, events, etc.) To get it working properly with YEP_ItemCore, I had to alias a few methods and overwrite getIndependentItem() function.
----- Speaking of YEP_ItemCore -----
I've discovered where the changeEquip is coming from.... line 1000 of YEP_ItemCore = equipInitIndependentEquips() function. Line 997 also seemed to have been missing a semicolon, but fixing that still gives me maximum call stack size exceeded error...
Code:
at JSON.stringify (<anonymous>)
at Function.JsonEx.stringify (rpg_core.js:8943)
at Function.JsonEx.makeDeepCopy (rpg_core.js:9014)
at Function.DataManager.registerNewItem (YEP_ItemCore.js:721)
at Game_Party.gainIndependentItem (LordV_ObjBasedSwVar.js:564)
at Game_Actor.equipInitIndependentEquips (YEP_ItemCore.js:997)
at Game_Actor.initIndependentEquips (YEP_ItemCore.js:963)
at Game_Actor.setup (YEP_ItemCore.js:958)
at Game_Actor.initialize (rpg_objects.js:3408)
at new Game_Actor (rpg_objects.js:3393)
The lines regarding 564 of my plugin is a copy of the original function (override) but with a small edit to save the item data to my storage as well for my scripts.

I have tested the skip title on/off, it has no effect (or rather not related to the issue).
if its part or aliasing the ItemCore of ObjSwVar, than place it underneath it, and not al to far on the bottom.

But other than that, I cant help you much with it. so I hope some can help you out. but it was a long shot of the title screen.
PROGRESS!!!! I got it(mostly) 😀 In short I:
- with LordV_ObjBasedSwVar below all of yanfly's scripts I had overwritten the changeEquip method. I included everything necessary and included a compatability section for YEP_EquipCore.
- with LordV_DynamicActors, I actually changed up quite a bit in its changeEquip method... lots of re-writing and organizing of how it meshes with the autoequip, my dynamic actors, etc.

The only thing remaining however now is with YEP_ItemCore and independent items. When I launch the game, it locks up on black screen and no console can be opened :\ but that is the remaining hurdle. With no independent items everything else was working fine.
UPDATE2: Well it's not initEquips()... at least not on my end. I commented out the alias'd method completely and it's still doing it. So that's 1 possibility eliminated. Only thousands more to go... lol

UPDATE: I still can't seem to figure out the freezing issue (game starts with black screen; locked up; can't access console), however, through one by one plugin ON/OFF testing I found out that my LordV_DynamicActors plugin with YEP_ItemCore(using independent items) are the conflicts... I would love to send the plugin off to someone if you're willing to test it, but I'm pretty sure without some of the setup (the character sprites, faces, battlers, variables, etc) you'd get a few errors 😛

So far I'm trying to look through the process, going through the motions (Game_Party.setupStartingMembers) and so on. If ANYONE has any ideas of why they might lock up (current thought is on the intialEquips sections... but could be anything past that as well), then I would love to hear some ideas :\
@lordvalinar Do NOT double post within 72 hours or you can get trouble if you do it alot of times. (maybe)

I would love to test your plugin out, but i dont use equip core or item core really, but i can make a clean project.
(not that i understand your plugin though)

But if Item core is the culplrit with your dynamic actor, check why not alias the part that is conflicting?
doesn't that solve some or most problems? Although, yanly use its own names, so idk if it can even conflict,
but still happen to most plugins.

here are some good coders around here, but if you have discord, why not ask it here? (only click here if you have discord though)
its a very helpfull server and I doubt anyone can help you there out 🙂
@lordvalinar Do NOT double post within 72 hours or you can get trouble if you do it alot of times. (maybe)

I would love to test your plugin out, but i dont use equip core or item core really, but i can make a clean project.
(not that i understand your plugin though)

But if Item core is the culplrit with your dynamic actor, check why not alias the part that is conflicting?
doesn't that solve some or most problems? Although, yanly use its own names, so idk if it can even conflict,
but still happen to most plugins.

here are some good coders around here, but if you have discord, why not ask it here? (only click here if you have discord though)
its a very helpfull server and I doubt anyone can help you there out 🙂

Whoops 72 hours not 48. I'll try my best not to do it again.

As far as new projects go, I made a fresh one and with the following plugins, turned on they work fine.... which means its not just YEP_ItemCore and DynamicActors.. there's something else conflicting:
- YEP_CoreEngine
- YEP_ItemCore
- YEP_EquipCore
- LordV_ObjBasedSwVar
- LordV_DynamicActors

And yeah I tried to alias (even override with ItemCore & EquipCore compatibility sections where necessary), so it's definitely something else conflicting. The other plugins I have between YEP's and mine are
- YEP_SkillCore
- YEP_StatusMenuCore
- YEP_KeyNameEntry
- YEP_KeyboardConfig
- YEP_TouchInputDisabler
then after: SRD_RemoveTitleScreen (which I -just- tested before posting this to make sure it wasn't that, and it didn't affect anything)

Yeah I'm on the discord I just rarely use it lol, but I'll post something there. See if anyone can help out, thanks 🙂

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/need-alternative-method-maybe-maximum-call-stack-error.110265/