Segmentation fault (wxString problem)

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
kornerr
Experienced Solver
Experienced Solver
Posts: 66
Joined: Wed Oct 12, 2005 2:43 pm
Location: Russia
Contact:

Segmentation fault (wxString problem)

Post by kornerr »

I get "Segmentation fault" when try to do

Code: Select all

map->skybox.back.filename = "string";
map is a pointer to Map class.
filename is of wxString class.
I can't understand what's wrong here, because when I do

Code: Select all

map->skybox.back.texid = 1
it doesn't cause the error.
texid is of GLint type.

I even tried to change filename to string type, not wxString class, but with no success. Even memset was done for skybox...

I'm at a loss what to do, and what can cause the error :(

Can anyone help me?

Thanks.

PS: Sources
(remove ".doc" from the filename)
The sources require wxWidgets and OpenGL (and Linux, or Cygwin under Windows)
Call "Map->Skybox->OK" and you will get "Segmentation fault".
Open Source all the way, baby ;)
OpenGameStudio
Image
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 »

is filename a pointer ?
kornerr
Experienced Solver
Experienced Solver
Posts: 66
Joined: Wed Oct 12, 2005 2:43 pm
Location: Russia
Contact:

Post by kornerr »

filename is of wxString class
Open Source all the way, baby ;)
OpenGameStudio
Image
jazz
Experienced Solver
Experienced Solver
Posts: 73
Joined: Thu Jun 09, 2005 12:37 am
Contact:

Post by jazz »

Maybe test it using the wxString::Append() function or similar instead of wxString::operator=. If there is a logical error forcing that may point you in the right direction or it won't compile.
[INSERT LAME SIG HERE]
chris
I live to help wx-kind
I live to help wx-kind
Posts: 150
Joined: Fri Oct 08, 2004 2:05 pm
Location: Europe

Post by chris »

Hi kornerr,

I did some debugging on your code and found the problem.

In the ctor of class Map you erase the struct skybox via

Code: Select all

memset (&skybox, 0, sizeof (skybox));
You can't do this with structs having instances of classes (wxString in this case), because you are then also erasing the pointer to the instances.

Another heed of warning: Also do not try to copy one struct with instances to another w/ memcpy or others. This will lead to similar problems.

HTH, chris
this->signature=NULL;
kornerr
Experienced Solver
Experienced Solver
Posts: 66
Joined: Wed Oct 12, 2005 2:43 pm
Location: Russia
Contact:

Post by kornerr »

Thanks very much, chris.
Can you tell me where did you know such "profound" things about C++?
I've only read Thinking in C++, vol1 (without polymorphism and templates :) )

Thanks.
Open Source all the way, baby ;)
OpenGameStudio
Image
chris
I live to help wx-kind
I live to help wx-kind
Posts: 150
Joined: Fri Oct 08, 2004 2:05 pm
Location: Europe

Post by chris »

Hi kornerr,

don't worry, deeper understanding of languages comes IMHO in greatest parts by simply doing it -- it's a bit like a recursion: you learn programming thru programming :wink:
I've got several years of OO programming (C++ and Java) on my back now, but I still make errors. It just happens; make the best of it and learn thru your errors. Once you made one, remember how that happened, and next time you'll know better.
Regarding literature: I had some good experiences with the "in a nutshell" books from O'Reilly (e.g. see http://www.oreilly.com/catalog/cplsian/ for "C++ in a nutshell"). They aren't cheap, but good for both beginners and professionals.
It'll be hard at first, but I recommend reading thru all the core properties of a language at once. After that, you'll know where to look in the book if you got a problem with a specific part of a language.

HTH, Chris
this->signature=NULL;
kornerr
Experienced Solver
Experienced Solver
Posts: 66
Joined: Wed Oct 12, 2005 2:43 pm
Location: Russia
Contact:

Post by kornerr »

Thanks, chris.
Open Source all the way, baby ;)
OpenGameStudio
Image
Post Reply