1

So I have the cl_Page class:

class cl_Page{
    public:
    cl_Page(cl_LessonMoment *parent_param);
    cl_Page(cl_SoftRoot *parent_param);
    int parent_type;
    cl_LessonMoment *parent_lmoment;
    cl_SoftRoot *parent_softroot;

    char id[256];

    //<content>
    //Backgrounds.
    str_Color bgcolor;
    cl_Image bgimage;

    //Actual content
    vector<cl_Textbox> textboxes;
    vector<cl_Button> buttons;
    vector<cl_Image> images;
    //</content>

    cl_Textbox* AddTextbox();
    cl_Button* AddButton();
    cl_Image* AddImage(char *filename = nullptr);
};

and the cl_Page constructors:

cl_Page::cl_Page(cl_LessonMoment *parent_param) : bgimage(nullptr){ //here is the segfault
    parent_lmoment = parent_param;
    parent_type = 1;
    id[0] = '\0';
    SetColor(bgcolor, 0xffffffff);
}

cl_Page::cl_Page(cl_SoftRoot *parent_param): bgimage(nullptr){ // or here if i call this constructor
    /*parent_softroot = parent_param;
    parent_type = 2;
    id[0] = '\0';
    SetColor(bgcolor, 0xffffffff);*/
}

What happens is that, no matter how I call the constructors, or no matter which one I call (the second is all commented out; so basically empty), global, local or dynamically, in a function or as a member object, I get a segmentation fault which appears to be right on the cl_Page::cl_Page(cl_LessonMoment *parent_param) : bgimage(nullptr){ line. The call stack looks like this:

#0 77C460CB strcat() (C:\WINDOWS\system32\msvcrt.dll:??)
#1 0022F168 ?? () (??:??)
#2 00401905 cl_Page::cl_Page(this=0x22fbe8, parent_param=0x0) (F:\Scoala\C++\EduSoftViewer_Parser\sources\classes\soft_tree\page.cpp:10)
#3 00402B8A main() (F:\Scoala\C++\EduSoftViewer_Parser\sources\main.cpp:11)

On some builds before I am writing this, (with exactly the same issue) the #1 position on the call stack, where now is ?? () (??:??) was ntdll!RtlDosApplyFileIsolationRedirection_Ustr() (C:\WINDOWS\system32\ntdll.dll:??).

So my question is: Does anybody know what is causing this? I really need to get this working.

If anything is unclear, just ask and I'll provide additional information.

EDIT: To clarify: I'm under Windows XP SP2 and running Code::Blocks with gcc.

EDIT 2: The cl_Image constructor:

cl_Image::cl_Image(char *filename_param){
    if (filename == nullptr){
        filename[0] = '\0';
    }
    else{
        strcpy(filename, filename_param);
    }
    SetPosition(position, 0, 0);
    id[0] = '\0';
    visible = 1;
    z_index = 0;
}

This class doesn't contain any object members, with the exception of a POD struct, position

EDIT 3: The cl_Image class:

class cl_Image{
public:
    cl_Image(char* filename_param = nullptr);


    str_Position position;
    char filename[256];
    char id[256];
    bool visible;
    int z_index;
};

str_Position is just a struct of 2 ints.

5
  • 3
    What goes on in "cl_image" constructor? Commented Feb 11, 2013 at 16:33
  • 1
    @EdwardB. care to show us what the filename member, id member, etc of cl_Image looks like? (for that matter, the entire class def would probably be handy) Commented Feb 11, 2013 at 16:40
  • @WhozCraig It's just a char array. Commented Feb 11, 2013 at 16:41
  • As it stands this should be closed as too localized without a doubt. You'll need to distill a more general situation you are dealing with. Commented Feb 11, 2013 at 16:42
  • 1
    @EdwardB. Its also never NULL, which is the reason you're going ker-boom. see below. Commented Feb 11, 2013 at 16:44

2 Answers 2

4

Pretty sure this is your problem:

cl_Image::cl_Image(char *filename_param){
    if (filename == nullptr){  // <<==== filename??? try using the param.
        filename[0] = '\0';
    }

Try this:

cl_Image::cl_Image(char *filename_param){
    if (filename_param == nullptr){
        filename[0] = '\0';
    }
Sign up to request clarification or add additional context in comments.

1 Comment

@EdwardB. Glad to hear it. For what its worth, I'd use a const char* param or const std::string& param and a std::string member for this, but I'm sure you have your reasons for not doing so. If not, consider it, and an initializer list for good measure.
0

I'll guess that bgimage can't be initialized with nullptr.

1 Comment

It can be initialized tis way. I just edited my question. You have the cl_Image constructor there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.