Segmentation Fault. Why I don't know.

This program crashes as soon as it hits the line below(please search for the word "CRASH" to see the line). I cant find out why.

Please help I am stuck. Thanks in advance.


+++++++++++++++++ Code Start ++++++++++++++++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
// File: lnun_engagement_manager.h
#include <string>

#include "lnun_ada_shooter_report_status.h"
#include "lnun_combat_status.h"
#include "lnun_current_world_model.h"
#include "lnun_direct_fire_status.h"
#include "lnun_operations_manager.h"
#include "lnun_intel_manager.h"
#include "lnun_taking_fire_status.h"
#include "lnun_timer_ticket.h"

namespace LNUN
{
    class EngagementManager : public IntelManager
    {
      public:

        EngagementManager::EngagementManager(SimulatedUnit &sim_unit);

        virtual ~EngagementManager(void);

        void initialize(void);
        
        void receive_direct_fire(const DirectFireStatus &);

        void receive_ada_fire(const AdaShooterReportStatus &);

        void receive_taking_fire(const TakingFireStatus &);

        bool receive_timer(const TimerResponseTrigger &);

        void reset_timer(void);

        void set_timer(void);

        void update_status(void);
        // --------------------------------------------------------------------
        // checkpoint/restart
        //
        LN::Serialize &save(LN::Serialize &) const;
        LN::Serialize &restore(LN::Serialize &);
        // class attributes
        
        std::map<LNMO::EgId, LN::SimTime>
            eg_ids_map;
        TimerTicket
            timer_ticket;
        LN::SimTime
            unknown_fire_time;
        const CombatStatus
            *combat_status_ptr;


      private:

        // --------------------------------------------------------------------
        // Declared as private to avoid copy construction.
        //
        EngagementManager(const EngagementManager &copy);
        EngagementManager &operator=(const EngagementManager &);
        
        void adjust_unit_entity_resolution(void);
        
        std::ostream &put_unit_entity_state(std::ostream &) const;
    };
}

#endif

//==========================   EngagementManager .CPP //   Implementation of the EngagementManager class.

// LN
#include "ln_detonation_types.h"

// UN
#include "lnun_current_world_model.h"
#include "lnun_log.h"
#include "lnun_engagement_manager.h"
#include "lnun_timer_response_trigger.h"
#include "lnun_timer_ticket.h"

namespace LNUN
{
    // ------------------------------------------------------------------------
    EngagementManager::EngagementManager(SimulatedUnit &sim_unit) :
        IntelManager(sim_unit),
        combat_status_ptr(0)
    {
    }

    // ------------------------------------------------------------------------
    //
    EngagementManager::~EngagementManager(void)
    {
    }

    // ------------------------------------------------------------------------
    //
    void EngagementManager::initialize(void)
    {
        Log
            high(UN_ESTIMATOR, LN::Logger::high, &current_world_model());
    
        IntelManager::initialize();
        
        combat_status_ptr = current_world_model().combat_status();
        
        if (not combat_status_ptr)
        {
            if (high.enabled())
            {
                high <<"combat_status_ptr is NULL";
                LNUN_LOG(high);
            }
        }

        reset_timer();
    }

    void EngagementManager::receive_direct_fire(
        const DirectFireStatus &status)
    {
         // **CRASH HERE**** 
        Log
            info(UN_ESTIMATOR, LN::Logger::info, &current_world_model()),
            debug(UN_ESTIMATOR, LN::Logger::debug, &current_world_model());

        const LN::SimTime
            status_time = status.get_status_time();
        const SubunitId
            subunit_firing;
            
        
        std::map<std::pair<LNMO::EgId, std::string>, std::string>::
            const_iterator
                itor = status.target_id_midb_list.begin();
    
        while(itor != status.target_id_midb_list.end())
        {
            LNMO::EgId
               target_eg = itor->first.first;

            std::map<LNMO::Idu, LN::SimTime>::iterator
                search_itor = eg_ids_map.find(target_eg);

            if (search_itor == eg_ids_map.end())
            {
                eg_ids_map[target_eg] = status_time;
            }
            else
            {
                eg_ids_map[search_itor->first]= status_time;
            }

            ++itor;
        }

  //====================== INTEL_MANAGER.H  =========================//
  
#ifndef LNUN_INTEL_MANAGER_H
#define LNUN_INTEL_MANAGER_H

// File: lnun_intel_manager.h

namespace LNUN
{
     class CurrentWorldModel;
     class IntelEstimatorAgent;

    // ------------------------------------------------------------------------
    class IntelManager
    {
      public:

        explicit IntelManager(SimulatedUnit &);

        virtual ~IntelManager(void);

         virtual void initialize(void);

        // --------------------------------------------------------------------
        // Read/write accessors 

        SimulatedUnit &update_unit(void);
        CurrentWorldModel &update_world_model(void);
        EnemyEstimate &update_estimate(void);
        SimulatedOrganicUnit &update_self(void);

        const SimulatedUnit &simulated_unit(void) const;
        const CurrentWorldModel &current_world_model(void) const;
        const EnemyEstimate &operations_estimate(void) const;
        const SimulatedOrganicUnit &self(void) const;

        bool alive(void) const;

      private:

        SimulatedUnit
            &the_unit;
        CurrentWorldModel
            &the_world_model;

        const EnemyEstimate
            *the_enemy_estimate;
        IntelEstimatorAgent
            *the_estimator_agent;

        int
            alive_signature;
    };
}

#endif
  //====================== INTEL_MANAGER.CPP
// File: lnun_operations_manager.cpp

#include "lnmo_logit.h"

#include "lnun_asset_manager.h"
#include "lnun_communication_manager.h"
#include "lnun_current_world_model.h"
#include "lnun_fo_interface_manager.h"
#include "lnun_message_req.h"
#include "lnun_enemy_estimate.h"
#include "lnun_intel_estimator_agent.h"
#include "lnun_simulated_organic_unit.h"
#include "lnun_simulated_unit.h"
#include "lnun_supply_manager.h"
#include "lnun_subordinate_manager.h"
#include "lnun_task_org_manager.h"
#include "lnun_zone_manager.h"

namespace LNUN
{
    IntelManager::IntelManager(SimulatedUnit &sim_unit) :
        the_unit(sim_unit),
        the_world_model(the_unit.current_world_model()),
        the_enemy_estimate(0),
        the_estimator_agent(0),
        alive_signature(0xdeadbeef)
    {
        if (not sim_unit.valid())
        {
            if (LNMO::LogIt::get(UN_ESTIMATOR))
            {
                LOG(info, "simulatedUnit(passed in) reference is invalid");
            }
        }

        if (not the_unit.valid())
        {
            if (LNMO::LogIt::get(UN_ESTIMATOR))
            {
                LOG(info, "simulatedUnit (class attrib) reference is invalid");
            }
        }
        
        if (not the_world_model.is_valid())
        {
            if (LNMO::LogIt::get(UN_ESTIMATOR))
            {
                LOG(info, "the_world_model reference is invalid");
            }
        }
    }
    
    IntelManager::~IntelManager(void)
    {
        alive_signature = 0x0;
    }

    void IntelManager::initialize(void)
    {
        if (LNMO::LogIt::get(UN_ESTIMATOR))
        {
            LOG(info, "initialize()");
        }

        the_enemy_estimate = 
            &(the_world_model.update_estimate()->enemy());
        the_estimator_agent = 
            &(the_unit.estimator_agent().intel_estimator);

        if (not the_enemy_estimate)
        {
            LOG(fatal, "Pointer to EnemyEstimate is null!");
        }

        if (not the_estimator_agent)
        {
            LOG(fatal, "Pointer to IntelEstimatorAgent is null!");
        }
    }

    bool IntelManager::alive(void) const
    {
        return (alive_signature == 0xdeadbeef);
    }

    SimulatedUnit &IntelManager::update_unit(void)
    {
        return the_unit;
    }

    CurrentWorldModel &IntelManager::update_world_model(void)
    {
        return the_world_model;
    }

    const CurrentWorldModel &IntelManager::current_world_model(void) const
    {
        return the_world_model;
    }

}
Last edited on
Where is the main function? How would we know why it is crashing if we can't see an actual entry point to the program as well as how the objects are constructed? A lot of times it is pretty obvious when you are debugging. Look for calls to null pointers or uninitialized pointers.

Also use comment line for the **crash here** comment. The way that you embedded that makes it impossible to see what that line of code was supposed to do.
Sorry about that. And thanks for your response.
The codebase is too large for me to include the main.
This segment of code is called whenever a unit is receiving direct fire. In the lnun_intel_manager.cpp constructor, you can see where the "the_world_model" is initialized and I have a log statement to say if it is valid or not and the "is invalid" log statement is never generated. So I am assuming that it is initialized. But when the ::receive_direct_fire(..) method is called that is when it crashes. if u have another email address i can send u some more code but this site is restricted to 9000 lines...
You should make a new program with a simple main function that instantiates the objects and and makes the same calls. try to duplicate the problem within a smaller example and post that. Is engagement manager instantiated? I see some stray lines that just say "Log" and I do not know what they are for. if you are using the debugger I'd take a look and see what the value of pointers are and figure out if you really have valid object pointers. I can't see what those logging functions do so I couldn't tell you what is wrong without a more complete example. many times the process of making a small example that duplicates the problem will help you find the problem for yourself.
The "Log" statement is our way of logging error messages to a central log file by severity. So "info" is just informational and "debug" is for developer debugging. I will try the smaller example like you mentioned and see what happens. Thanks.
Topic archived. No new replies allowed.