Seg fault when calling wxExecute

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
williamjcm
In need of some credit
In need of some credit
Posts: 4
Joined: Mon Oct 06, 2014 3:29 pm

Seg fault when calling wxExecute

Post by williamjcm » Sun Oct 19, 2014 12:12 pm

Hello.

I'm rather new to wxWidgets programming and I want to understand a segfault problem in my application.

I'm making a launcher for PCSX2 using Code::Blocks (nightly build from 16/09/2014) with wxSmith, MinGW 4.8.1 and wxWidgets 3.0.1 (Debug/Release SHARED=0 MONOLITHIC=1 UNICODE=1) under Windows 8.1 x64.

Sources: http://pastebin.com/PbvhS2Mu

The segfault is under the OnGameLaunch event, it happens when I click the "Launch Game" button.

Additional info:
-Ignore the _csv, I tried to use the StringTokenizer without success, and I was lazy to create a new project as a result;
-The content from gamelist.txt is an example;
-The for() loop just below ListBox1 = new wxListBox(...); is used to set the ListBox1 contents.
-The GameName[] and LaunchCommand[] arrays of wxStrings were originally members of a struct (code below):

Code: Select all

struct game
{
    wxString GameName;
    wxString LaunchCommand;
};

(snip)

game GameData[ListLineCount/2];
I hope it will be enough. If it isn't, don't hesitate to ask me.

Thanks in advance.

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

Re: Seg fault when calling wxExecute

Post by doublemax » Sun Oct 19, 2014 1:15 pm

For a start you should initialize "LBSelect" at the beginning.

Code: Select all

wxExecute(LaunchCommand[LBSelect], wxEXEC_ASYNC, NULL, NULL); // This is where I get a segfault.
When using a variable as index into an array, you shold make a range-check.

Code: Select all

wxString *LaunchCommand = new wxString[ListLineCount/2];
You're shadowing the member variable "LaunchCommand" with a local variable of the same name. The member variable will remain uninitialized.
Use the source, Luke!

williamjcm
In need of some credit
In need of some credit
Posts: 4
Joined: Mon Oct 06, 2014 3:29 pm

Re: Seg fault when calling wxExecute

Post by williamjcm » Sun Oct 19, 2014 4:03 pm

doublemax wrote:

Code: Select all

wxString *LaunchCommand = new wxString[ListLineCount/2];
You're shadowing the member variable "LaunchCommand" with a local variable of the same name. The member variable will remain uninitialized.
I think this is the case. wxArrayString seems to be the way to go.

Thank you.

EDIT: wxArrayString was the way to go.

Post Reply