Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mission Chain Nullptr #36586

Closed
araneyl opened this issue Dec 31, 2019 · 1 comment · Fixed by #37255
Closed

Mission Chain Nullptr #36586

araneyl opened this issue Dec 31, 2019 · 1 comment · Fixed by #37255
Labels
<Bug> This needs to be fixed Missions Quests and missions
Milestone

Comments

@araneyl
Copy link
Contributor

araneyl commented Dec 31, 2019

Describe the bug

In mission chains after some undetermined number of them a NullPtr is thrown when attempting to accept the next mission in a chain or if there is no defined next mission.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Find an NPC with a mission chain (multiple missions)
  2. Complete at least one mission
  3. Attempt to get the next mission in the chain
  4. NullPtr error appears in text.

Expected behavior

Presumably the NPC should give the next mission in the chain without issue. Or simply say he has no more missions for you if you reach the end of the chain.

Screenshots

Untitled

Versions and configuration

  • OS: Windows
    • OS Version: 10.0 1903
  • Game Version: 0.D-10878-g55987e0 [64-bit]
  • Graphics Version: Tiles
  • Mods loaded: [
    Dark Days Ahead [dda],
    Disable NPC Needs [no_npc_food]
    ]

Additional context

testddave.zip

This save will show the issue, simply speak to DDave and give him the cardboard and ask for the next mission in the chain.

As a reference, #35597 also shows this issue, though in that case it seems to happen after the second mission in the chain. I'm not sure why the difference yet.

@Night-Pryanik Night-Pryanik added <Bug> This needs to be fixed Missions Quests and missions labels Jan 5, 2020
@kevingranade kevingranade added this to the 0.E milestone Jan 13, 2020
@mlangsdorf
Copy link
Contributor

untested fix proposal:

diff --git a/src/npctalk.cpp b/src/npctalk.cpp
index d700556fa3..e61384eecd 100644
--- a/src/npctalk.cpp
+++ b/src/npctalk.cpp
@@ -726,20 +726,6 @@ void npc::talk_to_u( bool text_only, bool radio_contact )
             most_difficult_mission = type.difficulty;
         }
     }
-    if( chatbin.mission_selected != nullptr ) {
-        if( chatbin.mission_selected->get_assigned_player_id() != g->u.getID() ) {
-            // Don't talk about a mission that is assigned to someone else.
-            chatbin.mission_selected = nullptr;
-        }
-    }
-    if( chatbin.mission_selected == nullptr ) {
-        // if possible, select a mission to talk about
-        if( !chatbin.missions.empty() ) {
-            chatbin.mission_selected = chatbin.missions.front();
-        } else if( !d.missions_assigned.empty() ) {
-            chatbin.mission_selected = d.missions_assigned.front();
-        }
-    }
 
     // Needs
     if( has_effect( effect_npc_suspend ) ) {
@@ -785,6 +771,20 @@ void npc::talk_to_u( bool text_only, bool radio_contact )
     d_win.open_dialogue( text_only );
     // Main dialogue loop
     do {
+        if( chatbin.mission_selected != nullptr ) {
+            if( chatbin.mission_selected->get_assigned_player_id() != g->u.getID() ) {
+                // Don't talk about a mission that is assigned to someone else.
+                chatbin.mission_selected = nullptr;
+            }
+        }
+        if( chatbin.mission_selected == nullptr ) {
+            // if possible, select a mission to talk about
+            if( !chatbin.missions.empty() ) {
+                chatbin.mission_selected = chatbin.missions.front();
+            } else if( !d.missions_assigned.empty() ) {
+                chatbin.mission_selected = d.missions_assigned.front();
+            }
+        }
         d_win.print_header( name );
         const talk_topic next = d.opt( d_win, d.topic_stack.back() );
         if( next.id == "TALK_NONE" ) {
diff --git a/src/npctalk_funcs.cpp b/src/npctalk_funcs.cpp
index 57ab1a431a..9b3ce092d3 100644
--- a/src/npctalk_funcs.cpp
+++ b/src/npctalk_funcs.cpp
@@ -145,6 +145,9 @@ void talk_function::clear_mission( npc &p )
     }
     if( miss->has_follow_up() ) {
         p.add_new_mission( mission::reserve_new( miss->get_follow_up(), p.getID() ) );
+        if( !p.chatbin.mission_selected ) {
+            p.chatbin.mission_selected = p.chatbin.missions.front();
+        }
     }
 }

It's a little brute force, but it should force every dynamic line/response pair to have a valid mission_selected if there's one to be had. I don't think it should have any negative repercussions but it should be tested thoroughly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bug> This needs to be fixed Missions Quests and missions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants