所以我有 cl_Page 类:
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);
};
和 cl_Page 构造函数:
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);*/
}
发生的情况是,无论我如何调用构造函数,或者无论我调用哪个构造函数(第二个都被注释掉了;所以基本上是空的),全局的、局部的或动态的,在函数中或作为成员对象,我得到一个分段错误,似乎就cl_Page::cl_Page(cl_LessonMoment *parent_param) : bgimage(nullptr){
在线上。调用堆栈如下所示:
#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)
在我写这篇文章之前的一些构建中,(具有完全相同的问题)调用堆栈上的 #1 位置,现在?? () (??:??)
是ntdll!RtlDosApplyFileIsolationRedirection_Ustr() (C:\WINDOWS\system32\ntdll.dll:??)
.
所以我的问题是:有人知道是什么原因造成的吗?我真的需要让这个工作。
如果有任何不清楚的地方,请询问,我会提供更多信息。
编辑:澄清一下:我在 Windows XP SP2 下并使用 gcc 运行 Code::Blocks。
编辑 2: cl_Image 构造函数:
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;
}
此类不包含任何对象成员,POD 结构除外,position
编辑 3: cl_Image 类:
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
只是 2 个整数的结构。