Sunday, 15 June 2014

Segmentation fault in constructor in c++ -



Segmentation fault in constructor in c++ -

so have 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 cl_page constructors:

cl_page::cl_page(cl_lessonmoment *parent_param) : bgimage(nullptr){ //here 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 phone call constructor /*parent_softroot = parent_param; parent_type = 2; id[0] = '\0'; setcolor(bgcolor, 0xffffffff);*/ }

what happens that, no matter how phone call constructors, or no matter 1 phone call (the sec commented out; empty), global, local or dynamically, in function or fellow member object, segmentation fault appears right on cl_page::cl_page(cl_lessonmoment *parent_param) : bgimage(nullptr){ line. phone call stack looks 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 builds before writing this, (with same issue) #1 position on phone call stack, ?? () (??:??) ntdll!rtldosapplyfileisolationredirection_ustr() (c:\windows\system32\ntdll.dll:??).

so question is: know causing this? need working.

if unclear, inquire , i'll provide additional information.

edit: clarify: i'm under windows xp sp2 , running code::blocks gcc.

edit 2: 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 object members, exception of pod struct, position

edit 3: 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 struct of 2 ints.

pretty sure problem:

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

try this:

cl_image::cl_image(char *filename_param){ if (filename_param == nullptr){ filename[0] = '\0'; }

c++ constructor segmentation-fault

No comments:

Post a Comment