Skip to content

Add error handling for makeStatEquivalentCopy in CardBuffer to increase cross-mod compatibility #29

@Ind-E

Description

@Ind-E

} else {
this.noFurtherUpgrade = false;
AbstractCard upgradedCard = card.makeStatEquivalentCopy();
upgradedCard.upgrade();
upgradedCard.isLocked = card.isLocked;

calling makeStatEquivalentCopy here can occasionally crash the games when interacting with interacting with modal choice cards from other mods. BaseMod tries to autogenerate a makeCopy method for custom cards, but will throw a runtime exception if the card doesn't have a 0-argument constructor:

@Override
	public AbstractCard makeCopy() {
		try{
			return this.getClass().newInstance();
		}catch(InstantiationException | IllegalAccessException e) {
			throw new RuntimeException("BaseMod failed to auto-generate makeCopy for card: " + cardID);
		}
	}

Source: https://github.com/daviscook477/BaseMod/blob/26de1afc1a8ea7595b61f940de0ac29650f2c025/mod/src/main/java/basemod/abstracts/CustomCard.java#L55-L62

I've seen a user report this on the StS discord.

While it's possible to fix these issues by adding a makeCopy method to the offending cards, like in this pr, that requires action to be taken by each offending mod, which isn't likely. It'd be better to add some error handling around the makeStatEquivalentCopy call to increase cross-mod compatibility.

I would make a pr myself, but I'm not quite sure what the behaviour should be in the case a runtime exception is caught.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions