Files
Goober5000andClaude Opus 5 09fc7055b5 Fix FRED and qtFRED memory leaks at exit (#7784)
Neither editor had a teardown to match FSO's game_shutdown(), so the engine
data they set up was never freed.  Add editor_free_engine_data() to free it,
and call it from a new fred_shutdown() in FRED and from qtFRED's shutdown(),
before the graphics system closes.

Also:
- Delete FRED's modeless editors if they are still open at exit.
- Make FRED's dialog tooltips and sexp tree image lists members, since
  they were leaked or depended on OnDestroy() being called.
- Parent qtFRED's item models so they are deleted with their widgets.
- Enable the CRT leak report in qtFRED, which previously had none.
- In qtFRED, call shutdown() last in closeEvent(), since it destroys the
  window.
- Make the preferences path and user SID strings function-level statics,
  so MFC's leak dump no longer reports them as leaks.

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
2026-09-21 05:12:35 +02:00

140 lines
4.0 KiB
C++

/*
* Copyright (C) Volition, Inc. 1999. All rights reserved.
*
* All source code herein is the property of Volition, Inc. You may not sell
* or otherwise commercially exploit the source or things you created based on the
* source.
*
*/
// CampaignEditorDlg.h : header file
//
#include "resource.h"
#include "sexp_tree_view.h"
#include "CampaignFilelistBox.h"
/////////////////////////////////////////////////////////////////////////////
// campaign_editor form view
#ifndef __AFXEXT_H__
#include <afxext.h>
#endif
class campaign_sexp_tree : public sexp_tree_view
{
};
class campaign_editor : public CFormView, public SexpTreeEditorInterface
{
private:
int m_num_links;
int m_last_mission;
CString m_current_campaign_path;
CString GetPathWithoutFile() const;
protected:
campaign_editor(); // protected constructor used by dynamic creation
DECLARE_DYNCREATE(campaign_editor)
// SexpTreeEditorInterface overrides
public:
bool requireCampaignOperators() const override { return true; }
int onRootDeleted(int formula_node) override;
void onRootInserted(int old_formula, int new_formula) override;
void onRootMoved(int node1, int node2, bool insert_before) override;
SCP_vector<SCP_string> getMissionNames() override;
bool hasDefaultMissionName() override;
SCP_vector<SCP_string> getMissionGoals(const SCP_string& reference_name) override;
SCP_vector<SCP_string> getMissionEvents(const SCP_string& reference_name) override;
// Form Data
public:
void mission_selected(int num);
void insert_handler(int old, int node);
void move_handler(int node1, int node2, bool insert_before);
void update();
void load_tree(int save = 1);
void save_tree(int clear = 1);
void initialize( bool init_files, bool clear_path );
void load_campaign(const char *filename, const char *full_path);
void update_loop_desc_window();
void save_loop_desc_window();
//{{AFX_DATA(campaign_editor)
enum { IDD = IDD_CAMPAIGN };
campaign_sexp_tree m_tree;
campaign_filelist_box m_filelist;
CString m_name;
int m_type;
CString m_num_players;
CString m_desc;
CString m_branch_desc;
CString m_branch_brief_anim;
CString m_branch_brief_sound;
BOOL m_custom_tech_db;
//}}AFX_DATA
void SetCurrentCampaignPath(const CString& path);
const CString &GetCurrentCampaignPath() const;
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(campaign_editor)
public:
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
//}}AFX_VIRTUAL
// Implementation
protected:
virtual ~campaign_editor();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
CToolTipCtrl m_SubstituteMainHallToolTip;
// Generated message map functions
//{{AFX_MSG(campaign_editor)
afx_msg void OnLoad();
afx_msg void OnAlign();
afx_msg void OnCpgnClose();
afx_msg void OnRclickTree(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnBeginlabeleditSexpTree(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnEndlabeleditSexpTree(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnSelchangedSexpTree(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnMoveUp();
afx_msg void OnMoveDown();
afx_msg void OnEndEdit();
afx_msg void OnChangeBriefingCutscene();
afx_msg void OnSelchangeType();
afx_msg void OnToggleLoop();
afx_msg void OnBrowseLoopAni();
afx_msg void OnBrowseLoopSound();
afx_msg void OnChangeMainHall();
afx_msg void OnChangeSubstituteMainHall();
afx_msg void OnChangeDebriefingPersona();
afx_msg void OnCustomTechDB();
afx_msg void OnCustomData();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
extern campaign_editor *Campaign_tree_formp;
extern int Cur_campaign_mission;
extern int Cur_campaign_link;