wxWidget memory Leak, Please help!!!

Hi everyone, I am making a paint program on wxWidgets and it has a memory leak. When I compile the program there is no error but when I run it it just shut its self down.


I think it's something to do with the 2 pointers I created and how I used them here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class MyFrame : public wxFrame
{
	public:
	// Constructor
	MyFrame(const wxString& title, long style=wxDEFAULT_FRAME_STYLE);
	// Event handlers
	void OnMouseDown(wxMouseEvent& event);
	void OnMouseUp(wxMouseEvent& event);
	void Undo(wxCommandEvent& event);
	private:
	wxPoint *Start;
	wxPoint *End;
	// This class handles events
	DECLARE_EVENT_TABLE()
};



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void MyFrame::OnMouseDown(wxMouseEvent& event)
{
	wxClientDC Paint(this);
	*Start = event.GetLogicalPosition(Paint);
	Start++;
}
void MyFrame::OnMouseUp(wxMouseEvent& event)
{
	wxClientDC Paint(this);
	*End = event.GetLogicalPosition(Paint);
	Paint.DrawLine(*Start,*End);
	End++;
}
void MyFrame::Undo(wxCommandEvent& event)
{
	wxClientDC Paint(this);
	Paint.SetBrush(Paint.GetBackground());
	Paint.DrawLine(*Start,*End);
	*Start--;
	*End--;
}
Last edited on
closed account (S6k9GNh0)
A memory leak usually doesn't have a program shutdown as it's not immediately dangerous.
What you're doing though is causing a segmentation fault (probably) by writing to memory your application may not own. *Start and *End is set to garbage and so you're assigning to garbage locations. You need to set *Start and *End to something useful.
thanks mate!
Topic archived. No new replies allowed.