[fixed]Ring of Xathrid crash upon equipping token
Moderators: BAgate, drool66, Aswan jaguar, gmzombie, stassy, CCGHQ Admins
[fixed]Ring of Xathrid crash upon equipping token
by gnomefry » 02 Nov 2020, 21:32
Describe the Bug:
The game crashes when attempting to equip a creature token with Ring of Xathrid
Which card behaved improperly?
Ring of Xathrid
Which update are you using? (date, name)Which type? (duel, gauntlet, sealed deck)
version 10-2020 ee04575f - gauntlet
What exactly should be the correct behavior/interaction?
It can equip creature tokens
Are any other cards possibly affected by this bug?
Unknown
The game crashes when attempting to equip a creature token with Ring of Xathrid
Which card behaved improperly?
Ring of Xathrid
Which update are you using? (date, name)Which type? (duel, gauntlet, sealed deck)
version 10-2020 ee04575f - gauntlet
What exactly should be the correct behavior/interaction?
It can equip creature tokens
Are any other cards possibly affected by this bug?
Unknown
- Attachments
-
- ringofxathrid.rar
- (2.56 KiB) Downloaded 151 times
Last edited by drool66 on 04 Nov 2020, 20:39, edited 2 times in total.
Reason: confirmed
Reason: confirmed
Re: [confirm]Ring of Xathrid crash upon equipping token
by drool66 » 02 Nov 2020, 23:54
Confirmed in your save. Doesn't cause a problem in a clean game equipping spirit tokens from Abzan Ascendancy, nor the few other tokens I tried it on.
The latest images for Manalink will be here.
The latest Manalink installation directory will be here. Well, not quite, anymore. Check the latest patches.
The latest Manalink installation directory will be here. Well, not quite, anymore. Check the latest patches.
-
drool66 - Programmer
- Posts: 1163
- Joined: 25 Nov 2010, 22:38
- Has thanked: 186 times
- Been thanked: 267 times
Re: [confirm]Ring of Xathrid crash upon equipping token
by Korath » 03 Nov 2020, 00:52
Without debug data, I can't tell for sure if this is the specific problem here; but causing an equipment to leave the bf after activating it to equip but before resolution consistently segfaults. The Sundering Growth in the AI's hand is sufficient, if it tries to destroy your Ring of Xathrid in response.
The problem is that equip_target_creature() doesn't verify the equipment is still valid before calling call_card_function(...EVENT_EQUIPMENT_ATTACHED) with it. The quick fix is to change call_card_function() and call_card_function_i() to check if instance->internal_card_id == -1, and use instance->backup_internal_card_id instead if so.
call_card_fn() should really pop up a backtrace the way get_card_instance() does if it's called with address==NULL or something else that's not in Magic.exe's or ManalinkEh.dll's ranges, too.
The problem is that equip_target_creature() doesn't verify the equipment is still valid before calling call_card_function(...EVENT_EQUIPMENT_ATTACHED) with it. The quick fix is to change call_card_function() and call_card_function_i() to check if instance->internal_card_id == -1, and use instance->backup_internal_card_id instead if so.
call_card_fn() should really pop up a backtrace the way get_card_instance() does if it's called with address==NULL or something else that's not in Magic.exe's or ManalinkEh.dll's ranges, too.
-
Korath - DEVELOPER
- Posts: 3707
- Joined: 02 Jun 2013, 05:57
- Has thanked: 496 times
- Been thanked: 1106 times
Re: [confirm]Ring of Xathrid crash upon equipping token
by drool66 » 04 Nov 2020, 00:30
Did all the above, which included moving the show_backtrace() declaration to manalink.h. I wasn't sure if "SetVoidPtr already_displayed" should be declared globally or not (or maybe the card_instance_t and call_card_function stuff moved to the same file), so call_card_fn looks in part like this:
- Code: Select all
SetVoidptr has_been_displayed = NULL;
int call_card_fn_impl(CardFunction address, card_instance_t* instance, int player, int card, event_t event); // never call directly
// Puts instance into esi, then calls address(player, card, event).
int call_card_fn(CardFunction address, card_instance_t* instance, int player, int card, event_t event)
{
if ((card < 0 || card >= 150 || player < 0 || player > 1)
&& SetVoidptr_insert(&has_been_displayed, __builtin_return_address(0)))
{
char buf[100];
sprintf(buf, "call_card_fn(%d, %d)", player, card);
show_backtrace("bad parameters", buf);
}
int old_trigger_condition = trigger_condition;
etc...
The latest images for Manalink will be here.
The latest Manalink installation directory will be here. Well, not quite, anymore. Check the latest patches.
The latest Manalink installation directory will be here. Well, not quite, anymore. Check the latest patches.
-
drool66 - Programmer
- Posts: 1163
- Joined: 25 Nov 2010, 22:38
- Has thanked: 186 times
- Been thanked: 267 times
Re: [confirm]Ring of Xathrid crash upon equipping token
by Korath » 04 Nov 2020, 01:04
Checking player and card might make sense in call_card_function(), if we'd been seeing that called with bad values for them, but we haven't been.
On the other hand, it's not necessarily incorrect to call call_card_fn() with player or card outside their normal ranges, or even with instance being NULL. (get_pt_for_creature_with_variable_pt(), for example, does two of those three.) Its only precondition is that address is a callable function pointer. The closest we can come to testing that - short of just trying to call it anyway and segfaulting, like we currently are - is to check it's in a sane range: either between 0x401000 and 0x4ea000 for Magic.exe, or between 0x2001000 and &etext for ManalinkEh.dll.
edit: You've got to declare etext weird in 32-bit Windows builds, since the ABI normally prepends symbols with an underscore:
On the other hand, it's not necessarily incorrect to call call_card_fn() with player or card outside their normal ranges, or even with instance being NULL. (get_pt_for_creature_with_variable_pt(), for example, does two of those three.) Its only precondition is that address is a callable function pointer. The closest we can come to testing that - short of just trying to call it anyway and segfaulting, like we currently are - is to check it's in a sane range: either between 0x401000 and 0x4ea000 for Magic.exe, or between 0x2001000 and &etext for ManalinkEh.dll.
edit: You've got to declare etext weird in 32-bit Windows builds, since the ABI normally prepends symbols with an underscore:
- Code: Select all
extern char etext __asm__("etext");
-
Korath - DEVELOPER
- Posts: 3707
- Joined: 02 Jun 2013, 05:57
- Has thanked: 496 times
- Been thanked: 1106 times
Re: [confirm]Ring of Xathrid crash upon equipping token
by drool66 » 04 Nov 2020, 06:13
Thanks for that, probably saved me about an hour.
So this:
So this:
- Code: Select all
SetVoidptr has_been_displayed = NULL;
extern char etext __asm__("etext");
int call_card_fn_impl(CardFunction address, card_instance_t* instance, int player, int card, event_t event); // never call directly
// Puts instance into esi, then calls address(player, card, event).
int call_card_fn(CardFunction address, card_instance_t* instance, int player, int card, event_t event)
{
if ((address < (CardFunction)0x401000 || (address > (CardFunction)0x4ea000 && address < (CardFunction)0x2001000) || address > (CardFunction)&etext))
{
char buf[100];
sprintf(buf, "call_card_fn(%p)", address);
show_backtrace("bad parameters", buf);
}
The latest images for Manalink will be here.
The latest Manalink installation directory will be here. Well, not quite, anymore. Check the latest patches.
The latest Manalink installation directory will be here. Well, not quite, anymore. Check the latest patches.
-
drool66 - Programmer
- Posts: 1163
- Joined: 25 Nov 2010, 22:38
- Has thanked: 186 times
- Been thanked: 267 times
Re: [confirm]Ring of Xathrid crash upon equipping token
by drool66 » 04 Nov 2020, 20:38
Committed in d96155c
The latest images for Manalink will be here.
The latest Manalink installation directory will be here. Well, not quite, anymore. Check the latest patches.
The latest Manalink installation directory will be here. Well, not quite, anymore. Check the latest patches.
-
drool66 - Programmer
- Posts: 1163
- Joined: 25 Nov 2010, 22:38
- Has thanked: 186 times
- Been thanked: 267 times
7 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 67 guests