Fix for FE6 crash when loading unused portraits in dialogue?

I’ve been working on a personal FE6 hack using FEBuilderGBA that, among other things, incorporates some of the unused boss portrait recolors in speaking roles. However, this has led me to the realization that FE6 appears to have an incredibly inconvenient bug/programming quirk which causes the game to crash when loading any of these unused portraits for actual dialogue. The specific crash I get, running on mGBA, is

The game has crashed with the following error:
Jumped to invalid address: 97043050

Several instances of this message pop up consecutively, and the game is completely locked up beneath them.

Here’s the raw text of the battle quote in question. I tried setting it on Damas to confirm that it is something wrong with the text data rather than the unit it’s tied to, and it crashes the exact same way on him, too. Damas’s normal boss quote works, well, normally, so it’s not that boss quotes in general have gotten messed up somehow, either.

[LoadFace][0x1CC]Who do you think you are?[A]
You think you can stand
up to Frank the Fiend?[A]

As seen here, the specific portrait causing the crash in this case is portrait 0xCC, the green-haired Henning/Randy recolor with beige armor and a yellow shirt. Changing the portrait to a used one (0xC9, Randy’s portrait) fixed the crash, so it is tied to the specific portrait the game is being told to load here.

If it’s relevant, the boss quote is located in text slot 0x5, though I didn’t expect that to be a problem since Damas’s own boss dialogue is at 0xE and the text for Chapter 1 is at the very beginning of the text index.

I’m not finding anything in the “Patch” tab to fix it, and @Vesly’s patch to store conversation portrait IDs as shorts instead of bytes doesn’t seem to do anything to address the issue, either. @Brunhilda’s Project Ember incorporates new units with new portraits in speaking roles without replacing anybody, so I’d imagine they got this issue figured out for that hack, or at least found a workaround.

Any help is appreciated!

Might be a longshot here, but try adding [.] before the LoadFace or at the end of the convo to make sure the bytes are 2-aligned.

I think this is unlikely to fix it, but it’s worth trying.

I know huffman and sjis encoded text needs to be in 2 byte chunks, and [.] is necessary for [SetName] in some cases.

Just tried it; unfortunately, the error persists unchanged. I appreciate the suggestion, though!

I tried triggering your dialog as the battle quote for Damas with the dialog in text slot 0x5 and the vanilla game didn’t have any issue loading the dialog.

It could be a patch specific issue. If you’re using patches you could try installing the patches one at a time and testing them to see if you can reproduce the error in the vanilla game with the patch installed.

If you can’t reproduce the error in the vanilla game even with patches installed then the problem should be something specific to your hack. The error that you mentioned “Jumped to invalid address” likely means the game either tried to read from the wrong location in the ROM (such as with a bug introduced by a patch) or the game read the right location but the location contained the wrong data. The game was expecting to load an address from there but it found something else instead.

If you added your own data to the game you could check to see if you accidentally overwrote something, possibly an address pointer since the game failed a jump.

I hope that helps.

I believe it’s tied to the English translation patch. I tested it the exact same way (changing the portrait called for Damas’s boss quote to 0xCC and initiating a battle against him) in both an otherwise-clean Japanese ROM and a ROM patched with Gringe’s English translation and nothing else, and it ran fine in the Japanese ROM but caused the crash in the fan translation.

My guess would be that the modifications the fan translation makes to the text engine included making their own portrait pointer table that only includes portraits used in the final game, since the failed jump seems to be exactly the same regardless of which unused portrait is called, which tells me they’re likely all being handled the same way (probably a blanked-out entry in a pointer table).

EDIT: Upon inspection, the old FE6 translation doesn’t have the crash, either. Pretty sure it is something that was introduced in Gringe and the team’s updated translation patch.

Alright I think I got it. You’re right it is that patch. Using portrait 0xCC in a dialog will cause the game to crash because when you save the new dialog FE Builder will store the dialog as unencoded text and the Anti-Huffman patch in this translation is broken. So it’s not specifically this portrait, any unencoded text will cause the game to crash. I tried uninstalling the Anti-Huffman patch and re-installing it and the dialog did work but I don’t know if doing that will cause any problems later on. The safest work around would probably be to just have all of your text Huffman encoded. However that might have it’s own issues, I don’t know if “CC” is in the Huffman Dictionary for example. Either way I think re-installing the Anti-Huffman patch or encoding all your text are your best options.

Huh, this fixed it!

I feel a little silly for not trying this sooner, but thanks a bunch for figuring it out!

Yeah you bet.

…Hmm, but it’s still crashing for other text strings… Doing this makes it work for Damas’s battle quote, but not for custom dialogue.

Yeah, there might have been a reason why they disabled the Anti-Huffman patch, from what I saw it looks like it was there originally but it’s not complete. They may have overwritten it later. I don’t know if there’s a way to tell FE Builder to encode all text or I would suggest giving that a try.

After some more discussion in the Discord server, it turns out that installing @Vesly’s ReplaceText hack seems to fix the issue!

Thanks so much to the both of you for all your help!