Skip to content

pop talker from dialogue if they are dead#85935

Open
GuardianDll wants to merge 1 commit intomasterfrom
pop_talker
Open

pop talker from dialogue if they are dead#85935
GuardianDll wants to merge 1 commit intomasterfrom
pop_talker

Conversation

@GuardianDll
Copy link
Copy Markdown
Member

Summary

None

Purpose of change

Received next EoC from modder

  {
    "type": "effect_on_condition",
    "id": "EOC_foobar",
    "//": "n_ is the item",
    "effect": [
      "n_die",
      { "u_spawn_item": "another_item" },
    ]
  },

what it does is tries to spawn another_item, but u_spawn_item has a code that checks if opposite talker is presented, and if so, creates a popup "npc_name gives you Foo". Sadly in this case "n_die" killed our NPC before, but didn't made the dialogue aware about it, making this json result in crash

Describe the solution

Pop talker from dialogue if _die effect is used, so future code can safely use has_talker() and bail out if talker is not presented, or throw an error for calling talker when such do not exist anymore

Testing

Run the same code, instead of segfault, the game is properly guarded by has_talker(), do not try to access talker name and, therefore, do not segfault

@github-actions github-actions bot added NPC / Factions NPCs, AI, Speech, Factions, Ownership [C++] Changes (can be) made in C++. Previously named `Code` astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions labels Mar 18, 2026
@osuphobia
Copy link
Copy Markdown
Contributor

Mind also take a look at #85278 ?

Cataclysm-DDA/src/npctalk.cpp

Lines 2744 to 2764 in 817111b

talker *dialogue::actor( const bool is_beta ) const
{
if( !has_beta && !has_alpha ) {
debugmsg( "Attempted to use a dialogue with no actors! %s", get_callstack() );
}
if( is_beta && !has_beta ) {
debugmsg( "Tried to use an invalid beta talker. %s", get_callstack() );
// Try to avoid a crash by using the alpha if it exists
if( has_alpha ) {
return alpha.get();
}
}
if( !is_beta && !has_alpha ) {
debugmsg( "Tried to use an invalid alpha talker. %s", get_callstack() );
// Try to avoid a crash by using the beta if it exists
if( has_beta ) {
return beta.get();
}
}
return ( is_beta ? beta : alpha ).get();
}

Maybe it's better to also tweak dialogue::actor.

@GuardianDll
Copy link
Copy Markdown
Member Author

Lmao, yeah it's a bad fallback, unfortunately it is much bigger in scope than what i am fixing here, and i don't think there is a good way to resolve it overall except by terminating the quest in some way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

astyled astyled PR, label is assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions NPC / Factions NPCs, AI, Speech, Factions, Ownership

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants