#36 Specially with the situation at src/HexEditorFrame.cpp:498

open
nobody
Interface (15)
7
2014-08-28
2012-02-21
Anonymous
No

Hello,

I've done some wxWidgets development at past. I can't say this is a problem with wxWidgets library but please try:
Instead of creating dialog at heap, Could you please create it at stack?

Use:
else if( event.GetId() == idCompare ){
CompareDialog mcd(this);
mcd.ShowModal();

ifndef WXOSX // TODO: This leaks memory but OSX magically give error if I Destroy this.. Really Weird. Please help to fix this.

mcd.Destroy();

endif

}

Instead of:

else if( event.GetId() == idCompare ){
::CompareDialog *mcd = new CompareDialog( this );
mcd->ShowModal();

ifndef WXOSX // TODO: This leaks memory but OSX magically give error if I Destroy this.. Really Weird. Please help to fix this.

mcd->Destroy();

endif

}

Discussion

1 2 > >> (Page 1 of 2)

  • Anonymous
    2012-02-21

    At dialog code of wxWidgets at wxWidgets doc is more clear:

    Create dialog at stack and don't use destroy function:
    http://docs.wxwidgets.org/stable/wx_wxdialog.html

     
  • Death Knight®
    Death Knight®
    2012-02-21

    No, it doesn't work If I remember correctly.
    You can't call mcs.Destroy() normally or segmentation fault.

    I use this functions like that before. But as soon as current function returns, mcd destroyed automatically and lead same error...

    Somehow, MacOSX looks like destroy my class at the end of the ShowModal(), without using Destroy() code.
    It happens at some other function too.

    Actually Linux has same habit, before increasing stack size to 32MB from 8MB.
    I can't find how to increase stack on program manually, But increasing stack by hand via "ulimit -s 32000" doesn't help.

     
  • Death Knight®
    Death Knight®
    2012-02-21

    I already.
    Use of:

    else if( event.GetId() == idCompare ){
    CompareDialog mcd(this);
    mcd.ShowModal();
    } <-Segmentation Fault HERE due destructor

     

  • Anonymous
    2012-02-21

    What is your version of wxWidgets?

     
  • Death Knight®
    Death Knight®
    2012-02-21

    It doesn't differ. Same for 2.8.12 and 2.9.3

     

  • Anonymous
    2012-02-21

    I've implemented differently before. When ShowModal function called it is returning an id: keep this id private int in class at the end call endmodal as:

    dialogid is an int number that returns from ShowModal.

    model->EndModal(dialogid);

    I can send source code of application if you want.

     
  • Death Knight®
    Death Knight®
    2012-02-21

     
    Attachments

  • Anonymous
    2012-02-21

    For example:

    class MyDialog : public wxDialog {
    //I didn't write constructor implementation
    void setID(int id) {dialogid=id;}
    private:
    int dialogid
    };

    Lets create our dialog:
    MyDialog dialog(this);
    dialog.setID(dialog.ShowModal());

    When we finish our work with modal or at another function.
    We call at end:
    this->EndModal(dialogid);

    this->EndModal is implemented in MyDialog function

     
  • Death Knight®
    Death Knight®
    2012-02-21

    I attached picture about error.
    It tries to free already freed memory.

    Also ShowModal returns the values like wxOK wxCANCEL... when dialog is closed.
    EndModal just passing it parameter to ShowModal actually. I don't understand how could it fix this issue.
    it's nothing to do with memory pointers. I believe this is something related with compiler / MacOSX instead of my my code.

     
1 2 > >> (Page 1 of 2)