StackOverflowError with TriggeredManaAbility (Thread Stack Size)
- Dominant language
- Java
- Stars
- 2.4k
- Forks
- 940
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 160
Description
Interesting and rare error. Some `TriggeredManaAbility` contains mana effect and it triggers again and again too many times until StackOverflowError (see details below).
Related part of server side logs:
```
java.lang.StackOverflowError
...stream...
at java.util.stream.ReferencePipeline.allMatch(ReferencePipeline.java:454)
at mage.filter.predicate.Predicates$AndPredicate.apply(Predicates.java:152)
at mage.filter.FilterImpl.match(FilterImpl.java:38)
at mage.filter.FilterPermanent.match(FilterPermanent.java:54)
at mage.game.permanent.Battlefield.lambda$getActivePermanents$10(Battlefield.java:305)
...stream...
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
...normal code - start...
at mage.game.permanent.Battlefield.getActivePermanents(Battlefield.java:306)
at mage.cards.a.AshayaSoulOfTheWildEffect.apply(AshayaSoulOfTheWild.java:79)
at mage.abilities.effects.ContinuousEffectImpl.apply(ContinuousEffectImpl.java:117)
at mage.abilities.effects.ContinuousEffects.applyContinuousEffect(ContinuousEffects.java:1198)
at mage.abilities.effects.ContinuousEffects.applyLayer(ContinuousEffects.java:1160)
at mage.abilities.effects.ContinuousEffects.apply(ContinuousEffects.java:989)
at mage.game.GameState.applyEffects(GameState.java:681)
at mage.game.GameImpl.applyEffects(GameImpl.java:1858)
at mage.abilities.AbilityImpl.activate(AbilityImpl.java:243)
at mage.game.GameImpl.addTriggeredAbility(GameImpl.java:2062)
at mage.abilities.TriggeredAbilityImpl.trigger(TriggeredAbilityImpl.java:69)
at mage.abilities.TriggeredAbilities.checkTrigger(TriggeredAbilities.java:101)
at mage.abilities.TriggeredAbilities.checkTriggers(TriggeredAbilities.java:54)
at mage.game.GameState.handleEvent(GameState.java:866)
at mage.game.GameImpl.fireEvent(GameImpl.java:3293)
at mage.players.ManaPool.addMana(ManaPool.java:381)
at mage.players.ManaPool.addMana(ManaPool.java:344)
at mage.abilities.effects.mana.ManaEffect.addManaToPool(ManaEffect.java:60)
at mage.abilities.effects.mana.ManaEffect.apply(ManaEffect.java:50)
at mage.abilities.AbilityImpl.resolveMode(AbilityImpl.java:199)
at mage.abilities.AbilityImpl.resolve(AbilityImpl.java:183)
at mage.abilities.TriggeredAbilityImpl.resolve(TriggeredAbilityImpl.java:167)
...normal code - end...
...overflow code - start (calls multiple times)...
at mage.game.GameImpl.addTriggeredAbility(GameImpl.java:2063)
at mage.abilities.TriggeredAbilityImpl.trigger(TriggeredAbilityImpl.java:69)
at mage.abilities.TriggeredAbilities.checkTrigger(TriggeredAbilities.java:101)
at mage.abilities.TriggeredAbilities.checkTriggers(TriggeredAbilities.java:54)
at mage.game.GameState.handleEvent(GameState.java:866)
at mage.game.GameImpl.fireEvent(GameImpl.java:3293)
at mage.players.ManaPool.addMana(ManaPool.java:381)
at mage.players.ManaPool.addMana(ManaPool.java:344)
at mage.abilities.effects.mana.ManaEffect.addManaToPool(ManaEffect.java:60)
at mage.abilities.effects.mana.ManaEffect.apply(ManaEffect.java:50)
at mage.abilities.AbilityImpl.resolveMode(AbilityImpl.java:199)
at mage.abilities.AbilityImpl.resolve(AbilityImpl.java:183)
at mage.abilities.TriggeredAbilityImpl.resolve(TriggeredAbilityImpl.java:167)
...overflow code - end
```
I think it can be related to Thread Stack Size (`-Xss` java params) cause it's not real SOE -- it contains [[Ashaya, Soul of the Wild]] at the end, so "infinite" cycle with `TriggeredManaAbility` ends correctly.
Problem code that generates too much mana triggers:

TODO:
* find use case to reproduce;
* if it's a bugged card then fix it (e.g. it triggers on itself);
* if it's a normal use case then try to rework mana triggers processing (without recursive calls) or try to limit objects amount;
* if it's not possible then add default `-Xss` settings and instructions to the server;
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the StackOverflowError from the server-side trace, then inspect TriggeredManaAbility, ManaEffect, TriggeredAbilities, GameImpl, and AshayaSoulOfTheWildEffect at the referenced lines. Determine whether the card interaction triggers itself or whether recursive mana-trigger processing needs redesign; done means a confirmed cause and a tested fix or documented server stack-size handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend, game-dev
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100