Note that there are some explanatory texts on larger screens.

plurals
  1. POReason for segmentation fault, while using drag wxFileDropTarget
    text
    copied!<p>I try to do simple drag'n'drop (drag file to text area). I implemented drag'n'drop in 2 ways. Lets mark them <code>V1</code> and <code>V2</code>.</p> <p>In both versions drag'n'drop works OK, but in <code>V1</code> I get segmentation fault when I try to exit the application.</p> <h2>Question:</h2> <p>Maybe somebody could enlighten me why with <code>V1</code> I get segmentation faul, while no segmentation fault with <code>V2</code> ? (I have no real problem using <code>V2</code>, just want to know the reason why segmenation fault occurs)</p> <h2>Short descriptions of the versions:</h2> <ul> <li>V1 - There is one class named <code>Notepad</code>. It inherits from <code>wxFrame</code> and <code>wxFileDropTarget</code>, and encapsulates <code>wxTextCtrl</code> and implements <code>OnDropFiles(</code></li> <li>V2 - class <code>Notepad</code> ingerits only from <code>wxFrame</code> and encapsulates <code>wxTextCtrl</code>. Drang'n'drop is done by separate class called <code>DRPTARGET</code>, which inherits from <code>wxFileDropTarget</code> and implements <code>OnDropFiles(</code></li> </ul> <h2>Code for ilustration</h2> <p><sup>(I cut out a lot of code here, which was not relevant. I hope I did not cut out too much)</sup></p> <h3><code>V1</code>:</h3> <pre><code> #include &lt;wx/wx.h&gt; #include &lt;wx/dir.h&gt; #include &lt;wx/dnd.h&gt; class Notepad : public wxFrame , public wxFileDropTarget { public: Notepad(); private: wxTextCtrl* text_area; bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &amp;filenames); }; bool Notepad::OnDropFiles (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const wxArrayString &amp;filenames){ return this-&gt;text_area-&gt;LoadFile(filenames[0]); } Notepad::Notepad() : wxFrame(NULL, wxID_ANY, wxT("V1"), wxDefaultPosition, wxSize(650,500)) { wxBoxSizer *sizerh = new wxBoxSizer(wxHORIZONTAL); this-&gt;text_area = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER | wxTE_MULTILINE); sizerh-&gt;Add(this-&gt;text_area,1,wxEXPAND,0); this-&gt;SetSizer(sizerh); this-&gt;text_area-&gt;SetDropTarget(this); } </code></pre> <p><br/> <br/></p> <h3><code>V2</code>:</h3> <pre><code> #include &lt;wx/wx.h&gt; #include &lt;wx/dir.h&gt; #include &lt;wx/dnd.h&gt; class DRPTARGET : public wxFileDropTarget{ private: wxTextCtrl* text_area; bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &amp;filenames) { return this-&gt;text_area-&gt;LoadFile(filenames[0]); }; public: DRPTARGET(wxTextCtrl* text_area) { this-&gt;text_area = text_area; }; }; class Notepad : public wxFrame , public wxFileDropTarget { public: Notepad(); // our default constructor private: wxTextCtrl* text_area; }; Notepad::Notepad() : wxFrame(NULL, wxID_ANY, wxT("V2"), wxDefaultPosition, wxSize(650,500)) { wxBoxSizer *sizerh = new wxBoxSizer(wxHORIZONTAL); this-&gt;text_area = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER | wxTE_MULTILINE); sizerh-&gt;Add(this-&gt;text_area,1,wxEXPAND,0); this-&gt;SetSizer(sizerh); DRPTARGET* drop_target = new DRPTARGET(this-&gt;text_area); this-&gt;text_area-&gt;SetDropTarget(drop_target); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload