Runs on wxdevc++, but not on OS! Topic is solved

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
Lord Asriel
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Nov 17, 2011 1:28 am

Runs on wxdevc++, but not on OS!

Post by Lord Asriel » Mon Dec 05, 2011 11:34 pm

Hello all! I made a program, using wxwidgets (one dialog with a few controls in it including two richtext controls). When I F9 "Compile & Run" it, it runs PERFECTLY. However, when I run the .exe on my project's output folder, it most certainly doesn't! What could be causing such an irregularity?

A few more details(if needed I will post more): I have a couple of functions of type const char *. When I mess with my program's controls, I SetValue() each wxRixhTextCtrl to each of these functions. It works within the compiler, but not outside.

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: Runs on wxdevc++, but not on OS!

Post by Auria » Tue Dec 06, 2011 2:29 am

Most likely problem is a DLL that is not found, try using Dependency Walker to figure what DLL is missing and add it along the project
"Keyboard not detected. Press F1 to continue"
-- Windows

Lord Asriel
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Nov 17, 2011 1:28 am

Re: Runs on wxdevc++, but not on OS!

Post by Lord Asriel » Tue Dec 06, 2011 9:57 am

This is quite heavy-duty for me, I marginally know what a DLL is, so please be easy on me! I read the Dependency Walker's healp file, and I'm not sure what I should do. In the "Module List View", there are two entries, GPSVC.DLL and IESHIMS.DLL with "Error opening file, the system cannot find the file specified". Is that it? If so, what should I do? I searched my pc for files and did not find those.
It might be useful to note that, if I "profile" my .exe through Dependency Walker, it still gives wrong strings to the text controls, but this time different ones than when I run it alone (!).

User avatar
doublemax
Moderator
Moderator
Posts: 15294
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Runs on wxdevc++, but not on OS!

Post by doublemax » Wed Dec 07, 2011 11:52 pm

What exactly does "doesn't work" mean? Does your program not start at all or does it just behave differently?

In the latter case: What exactly?
Use the source, Luke!

Lord Asriel
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Nov 17, 2011 1:28 am

Re: Runs on wxdevc++, but not on OS!

Post by Lord Asriel » Thu Dec 08, 2011 9:48 am

The problem analytically: There is a single (wx)Button. When it is pressed, some of my routines may be run, some others not, but in the end the values of the two rich text controls are set to one of my functions each.
The program is about saving edges of a graph in a 2-D sparse array (linked list), creating a spanning tree on it, and finding cycles. Being 2D and double-link-listed, the members of the sparse array contain pointers to the previous, next, up and down elements. Also, the edges they represent could or could not be part of the spanning tree (STE=spanning tree edge). This is what const char* print_all_edges() is about, and sets WxRichTextCtrl_sparse->SetValue(print_all_edges()). Then, the program searches for cycles and reports them. This is what const char* const char* print_all_cycles(void) is about, and sets
WxRichTextCtrl_cycles->SetValue(print_all_cycles());

(Normal) Output after adding edges (1,0),(1,2),(2,0): (Note that the insert function inserts the symmetricals too, this is a bidirectional graph):
WxRichTextCtrl_sparse:
Edge (1,0):STE=1. P(x-): None N(x+): (2,0) U(y-): None D(y+): (1,2)
Edge (2,0):STE=1. P(x-): (1,0) N(x+): None U(y-): None D(y+): (2,1)
Edge (0,1):STE=1. P(x-): None N(x+): (2,1) U(y-): None D(y+): (0,2)
Edge (2,1):STE=0. P(x-): (0,1) N(x+): None U(y-): (2,0) D(y+): None
Edge (0,2):STE=1. P(x-): None N(x+): (1,2) U(y-): (0,1) D(y+): None
Edge (1,2):STE=0. P(x-): (0,2) N(x+): None U(y-): (1,0) D(y+): None

WxRichTextCtrl_cycles:
Graph cycle for edge (2,1):(spanning tree root: 0)
(0,2)->(2,1)<-(1,0)

Graph cycle for edge (1,2):
(0,1)->(1,2)<-(2,0)

Now, also consider the normal output after just inputting edge (1,0):
WxRichTextCtrl_sparse:
Edge (1,0):STE=1. P(x-): None N(x+): None U(y-): None D(y+): None
Edge (0,1):STE=1. P(x-): None N(x+): None U(y-): None D(y+): None

WxRichTextCtrl_cycles:
No cycles detected: Graph is a tree.

...and here''s the output, after just adding (1,0), that I get through running the program outside the IDE:
WxRichTextCtrl_sparse:
Edge (1,0):STE=1. P(x-): None N(x+): None U

WxRichTextCtrl_cycles:
No cycles detected: Graph is a tree.

This is the first and only time that the first routine "works a bit", then, any output on both windows is nothing, emptiness.

Here's some of the the code:

Code: Select all

void Sparse_Array_GUIDlg::WxButton1Click(wxCommandEvent& event)
{
	switch(WxRadioBox1->GetSelection())
	{
        case 1://Delete
            delete_edge(find_edge(WxSpinCtrl1->GetValue(),WxSpinCtrl2->GetValue()));
            break;
        case 0://Insert
            insert_edge(WxSpinCtrl1->GetValue(),WxSpinCtrl2->GetValue());
            break;
    }
    WxSpinCtrl_root->SetValue(validroot(WxSpinCtrl_root->GetValue()));//set root to a valid one
    create_spanning_tree(WxSpinCtrl_root->GetValue());
    create_all_cycles();
    WxRichTextCtrl_sparse->SetValue(print_all_edges());
    WxRichTextCtrl_cycles->SetValue(print_all_cycles());
}

Code: Select all

typedef struct pathmember * pp;
typedef struct edge * ep;//Edge Pointer

struct edge{
       int x,y;
       bool STE;
       pp p1,p2;
       ep prev,next,up,down;
};

struct nodetype{
       char STN;//(0:not STN)(1:STN, but (possibly) has neighbours that are not STN)(2:STN + neighbours=STN)
//1 are nodes of current spanning tree level search. 2 are old, 0 are future.
       bool TN;//if false, this node doesn't exist
       int parent;
};

struct pathmember{
    pathmember * next;
    ep target;
};

Code: Select all

const char* print_edge(ep temp, bool longmode)
{
       stringstream s;
       s.str("");//Initialization of s
       unsigned char x=2;
       if(longmode) s<<"Edge ";
       s<<"("<<temp->x<<","<<temp->y<<")";
       if(longmode) s<<":STE="<<temp->STE;
       if(longmode)
       {
           s<<".    P(x-): ";
           if(temp->prev) s<<"("<<temp->prev->x<<","<<temp->y<<")"; else s<<"None";
           s<<"  N(x+): ";
           if(temp->next) s<<"("<<temp->next->x<<","<<temp->y<<")"; else s<<"None";
           s<<"  U(y-): ";
           if(temp->up)   s<<"("<<temp->x<<","<<temp->up  ->y<<")"; else s<<"None";
           s<<"  D(y+): ";
           if(temp->down) s<<"("<<temp->x<<","<<temp->down->y<<")"; else s<<"None";
           s<<"\n";
       }
       return s.str().c_str();
}

Code: Select all

const char* print_all_edges()
{
    int i,j;
    string s="";
    ep temp;
    for(i=0;i<30;i++)
    {
        temp=SparseArrayVertical[i];
        while(temp)
        {
            s+=print_edge(temp);
            temp=temp->next;
        }
    }
    if(s=="") return "Sparse Array is empty";
    return s.c_str();
}

Code: Select all

const char* print_cycle(ep i)
{
    string s="Graph cycle for edge ";
    s+=print_edge(i,false);
    s+=":\n";
    //s+="\nPath 1/2: From joint to sentinel (forward):\n";
    do
    {
        s+=print_edge(i->p1->target,false);
        s+="->";
        i->p1=i->p1->next;
    }while(i->p1->next);
    s+=print_edge(i,false);
    //s+="Path 2/2: From joint to sentinel (backward):\n";
    /*do
    {
        s+="<-";
        s+=print_edge(i->p2->target,false);
        i->p2=i->p2->next;
    }while(i->p2->next);*/
    s+=reverse_path_print(i->p2);
    s+="\n\n";
    return s.c_str();
}

Code: Select all

const char* print_all_cycles(void)
{
    int i,j;
    string s="";
    ep temp;
    for(i=0;i<30;i++)
    {
        temp=SparseArrayVertical[i];
        while(temp)
        {
            if(temp->p1)
            {
                cout<<"Called: printcycle for edge: "<<print_edge(temp,false);
                s+=print_cycle(temp);
            }
            temp=temp->next;
        }
    }
    if(s=="") return "No cycles detected: Graph is a tree.";
    return s.c_str();
}

User avatar
doublemax
Moderator
Moderator
Posts: 15294
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Runs on wxdevc++, but not on OS!

Post by doublemax » Thu Dec 08, 2011 10:07 am

Code: Select all

const char* print_all_cycles(void)
{
    int i,j;
    string s="";
   [...]

    return s.c_str();
}
You can't return strings like this. You're returning the pointer to data in a local variable. At the end of this function, the pointer will be unvalid. At first sight this may work, depending an how and when you use the return value, but in general it's wrong.
Use the source, Luke!

Lord Asriel
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Nov 17, 2011 1:28 am

Re: Runs on wxdevc++, but not on OS!

Post by Lord Asriel » Thu Dec 08, 2011 1:17 pm

That was it! I changed the return type to string and it worked! Thanks a lot! Admin please mark as solved!

Post Reply