这是HomeWork
嘿我正在使用Gtkmm作为一个作业,我一直都很好,但是我在一个函数中得到一个奇怪的问题我用来填充TreeView你得到错误
(out:21185):GLib-ERROR **:/build/buildd/glib2.0-2.32.3/./glib/gmem.c:408:溢出分配3908326912 * 4字节 跟踪/断点陷阱(核心转储)
然而奇怪的部分是我使用这个函数为3个单独的TreeViews,它只是在我最近我写的我得到这个错误我已将问题隔离到行
*m_refTreeModel = Gtk::ListStore::create((*m_columns));
关于如何发生这种情况的任何想法?我的程序相当大,因此显示与此相关的所有源代码将难以上传。但是这条线的功能是
Controller.cpp
#include "Controller.h"
#include "ModelColumns.h"
#include <iostream>
Controller::Controller()
{
mainMenue = (MainMenueView*) new MainMenueView(this);
studentMenue = (StudentMenueView*) new StudentMenueView(this);
degreeMenue = (DegreeMenueView*) new DegreeMenueView(this);
underGradView = (UnderGradView*) new UnderGradView(this);
workExpView = (WorkExpView*) new WorkExpView(this);
relatedCourseView = (RelatedCourseView*) new RelatedCourseView(this);
tAExpView = (TAExpView*) new TAExpView(this);
referencesView = (ReferencesView*) new ReferencesView(this);
gradView = (GradView*) new GradView(this);
adminMenueView = (AdminMenueView*) new AdminMenueView(this);
viewPendingAppsMenue = (ViewPendingAppsMenue*) new ViewPendingAppsMenue(this);
pendingAppsView = (PendingAppsView*) new PendingAppsView(this);
assignMenueView = (AssignMenueView*) new AssignMenueView(this);
assignSuccessView = (AssignSuccessView*) new AssignSuccessView(this);
editLoginView = (EditLoginView*) new EditLoginView(this);
editAppView = (EditAppView*) new EditAppView(this);
//Setting up the window
set_title("");
set_border_width(10);
set_default_size(700,400);
//setting up the notebook
gui.set_border_width(10);
gui.set_show_tabs(false);
add(gui);
gui.append_page((*mainMenue));
gui.append_page((*studentMenue));
gui.append_page((*degreeMenue));
gui.append_page((*underGradView));
gui.append_page((*workExpView));
gui.append_page((*relatedCourseView));
gui.append_page((*tAExpView));
gui.append_page((*referencesView));
gui.append_page((*gradView));
gui.append_page((*adminMenueView));
gui.append_page((*viewPendingAppsMenue));
gui.append_page((*pendingAppsView));
gui.append_page((*assignMenueView));
gui.append_page((*assignSuccessView));
gui.append_page((*editLoginView));
gui.append_page((*editAppView));
show_all_children();
}
Controller::~Controller()
{
delete mainMenue;
delete studentMenue;
delete degreeMenue;
delete underGradView;
delete workExpView;
delete relatedCourseView;
delete tAExpView;
delete referencesView;
delete gradView;
delete adminMenueView;
delete viewPendingAppsMenue;
delete pendingAppsView;
delete assignMenueView;
delete assignSuccessView;
}
void Controller::fillTreeModel(const Glib::ustring &page, const Glib::ustring &type, const Glib::ustring type1)
{
ModelColumns *m_columns;
Gtk::TreeView *m_TreeView;
Glib::RefPtr<Gtk::ListStore> *m_refTreeModel;
std::string temp;
int tempNum;
if (page == "Pending")
{
m_columns = &(pendingAppsView -> m_columns);
m_TreeView = &(pendingAppsView -> m_TreeView);
m_refTreeModel = &(pendingAppsView -> m_refTreeModel);
}
else if (page == "Assign")
{
m_columns = &(assignSuccessView -> m_columns);
m_TreeView = &(assignSuccessView -> m_TreeView);
m_refTreeModel = &(assignSuccessView -> m_refTreeModel);
}
else if (page == "Edit")
{
m_columns = &(editAppView -> m_columns);
m_TreeView = &(editAppView -> m_TreeView);
m_refTreeModel = &(editAppView -> m_refTreeModel);
}
if (type1 == "Pending")
{
temp = "Pending";
}
if (type1 == "Student")
{
tempNum = stuNumHold;
}
else
{
temp = "";
}
//setting up the next page's treeView
if (type == "View All")
{
model.pendingApps.fillGrads(temp);
model.pendingApps.fillUnderGrads(temp);
}
else if (type == "Student")
{
model.pendingApps.fillGrads(tempNum);
model.pendingApps.fillUnderGrads(tempNum);
//std::cout << "here4" << std::endl;
}
else
{
std::string tbCourse = Glib::locale_from_utf8(type);
model.pendingApps.fillGrads(&tbCourse, temp);
model.pendingApps.fillUnderGrads(&tbCourse, temp);
}
//std::cout << model.pendingApps.underGrads[0].getStuNum() << "***" << std::endl;
*m_refTreeModel = Gtk::ListStore::create((*m_columns));
//std::cout << model.pendingApps.underGrads[0].getStuNum() << "***" << std::endl;
(*m_TreeView).set_model((*m_refTreeModel));
Gtk::TreeModel::Row row;
//std::cout << model.pendingApps.underGrads[0].getStuNum() << "***" << std::endl;
while (model.pendingApps.grads.front() != NULL || model.pendingApps.underGrads.front() != NULL)
{
//std::cout << "here" << std::endl;
Grad *tempGrad = model.pendingApps.grads.front();
UnderGrad *tempUnderGrad = model.pendingApps.underGrads.front();
std::string temp1, temp2;
if (model.pendingApps.grads.front() != NULL)
{
temp1 = (*tempGrad).getCourse();
}
if (model.pendingApps.underGrads.front() != NULL)
{
temp2 = (*tempUnderGrad).getCourse();
}
if (model.pendingApps.underGrads.front() != NULL && type == "View All" && (tempGrad == NULL || strcmp(temp1.c_str(), temp2.c_str()) > 0))
{
row = *((*m_refTreeModel) -> append());
row [m_columns -> m_col_appNum] = (*tempUnderGrad).getAppNum();
row [m_columns -> m_col_degree] = "Undergraduate";
row [m_columns -> m_col_course] = (*tempUnderGrad).getCourse();
row [m_columns -> m_col_first] = (*tempUnderGrad).getFName();
row [m_columns -> m_col_last] = (*tempUnderGrad).getLName();
row [m_columns -> m_col_email] = (*tempUnderGrad).getEmail();
row [m_columns -> m_col_major] = (*tempUnderGrad).getMajor();
row [m_columns -> m_col_field] = "";
row [m_columns -> m_col_sup] = "";
row [m_columns -> m_col_stuNum] = (*tempUnderGrad).getStuNum();
row [m_columns -> m_col_year] = (*tempUnderGrad).getYear();
row [m_columns -> m_col_gpa] = (*tempUnderGrad).getGPA();
row [m_columns -> m_col_cGPA] = (*tempUnderGrad).getCGPA();
row [m_columns -> m_col_app_status] = (*tempUnderGrad).getAppStatus();
model.pendingApps.underGrads.popFront();
}
else if (model.pendingApps.grads.front() != NULL && type == "View All" && (tempUnderGrad == NULL || strcmp(temp1.c_str(), temp2.c_str()) <= 0))
{
row = *((*m_refTreeModel) -> append());
row [m_columns -> m_col_appNum] = (*tempGrad).getAppNum();
row [m_columns -> m_col_degree] = "Graduate";
row [m_columns -> m_col_course] = (*tempGrad).getCourse();
row [m_columns -> m_col_first] = (*tempGrad).getFName();
row [m_columns -> m_col_last] = (*tempGrad).getLName();
row [m_columns -> m_col_email] = (*tempGrad).getEmail();
row [m_columns -> m_col_field] = (*tempGrad).getResearch();
row [m_columns -> m_col_sup] = (*tempGrad).getSupervisor();
row [m_columns -> m_col_stuNum] = (*tempGrad).getStuNum();
row [m_columns -> m_col_app_status] = (*tempGrad).getAppStatus();
model.pendingApps.grads.popFront();
}
else if (model.pendingApps.underGrads.front() != NULL && model.pendingApps.grads.front() != NULL && type != "View All")
{
row = *((*m_refTreeModel) -> append());
row [m_columns -> m_col_appNum] = (*tempGrad).getAppNum();
row [m_columns -> m_col_degree] = "Graduate";
row [m_columns -> m_col_course] = (*tempGrad).getCourse();
row [m_columns -> m_col_first] = (*tempGrad).getFName();
row [m_columns -> m_col_last] = (*tempGrad).getLName();
row [m_columns -> m_col_email] = (*tempGrad).getEmail();
row [m_columns -> m_col_field] = (*tempGrad).getResearch();
row [m_columns -> m_col_sup] = (*tempGrad).getSupervisor();
row [m_columns -> m_col_stuNum] = (*tempGrad).getStuNum();
row [m_columns -> m_col_app_status] = (*tempGrad).getAppStatus();
model.pendingApps.grads.popFront();
}
else
{
row = *((*m_refTreeModel) -> append());
row [m_columns -> m_col_appNum] = (*tempUnderGrad).getAppNum();
row [m_columns -> m_col_degree] = "Undergraduate";
row [m_columns -> m_col_course] = (*tempUnderGrad).getCourse();
row [m_columns -> m_col_first] = (*tempUnderGrad).getFName();
row [m_columns -> m_col_last] = (*tempUnderGrad).getLName();
row [m_columns -> m_col_email] = (*tempUnderGrad).getEmail();
row [m_columns -> m_col_major] = (*tempUnderGrad).getMajor();
row [m_columns -> m_col_field] = "";
row [m_columns -> m_col_sup] = "";
row [m_columns -> m_col_stuNum] = (*tempUnderGrad).getStuNum();
row [m_columns -> m_col_year] = (*tempUnderGrad).getYear();
row [m_columns -> m_col_gpa] = (*tempUnderGrad).getGPA();
row [m_columns -> m_col_cGPA] = (*tempUnderGrad).getCGPA();
row [m_columns -> m_col_app_status] = (*tempUnderGrad).getAppStatus();
model.pendingApps.underGrads.popFront();
}
}
}
或者Controller.h
#ifndef CONTROLLER_H
#define CONTROLLER_H
#include <gtkmm.h>
#include "MainMenueView.h"
#include "StudentMenueView.h"
#include "DegreeMenueView.h"
#include "UnderGradView.h"
#include "WorkExpView.h"
#include "RelatedCourseView.h"
#include "TAExpView.h"
#include "ReferencesView.h"
#include "GradView.h"
#include "AdminMenueView.h"
#include "ViewPendingAppsMenue.h"
#include "PendingAppsView.h"
#include "Model.h"
#include "AssignMenueView.h"
#include "AssignSuccessView.h"
#include "EditAppView.h"
#include "EditLoginView.h"
class MainMenueView;
class StudentMenueView;
class DegreeMenueView;
class UnderGradView;
class WorkExpView;
class RelatedCourseView;
class TAExpView;
class ReferencesView;
class GradView;
class AdminMenueView;
class ViewPendingAppsMenue;
class PendingAppsView;
class AssignMenueView;
class AssignSuccessView;
class EditAppView;
class EditLoginView;
class Controller : public Gtk::Window
{
public:
Controller();
virtual ~Controller();
Gtk::Notebook gui;
int appNumber, stuNumHold;
Glib::ustring degreeLevel, courseApplied, searchType;
Glib::ustring studentMode;
void fillTreeModel(const Glib::ustring&, const Glib::ustring&, const Glib::ustring);
Model model;
private:
MainMenueView *mainMenue; //0
StudentMenueView *studentMenue; //1
DegreeMenueView *degreeMenue; //2
UnderGradView *underGradView; //3
WorkExpView *workExpView; //4
RelatedCourseView *relatedCourseView; //5
TAExpView *tAExpView; //6
ReferencesView *referencesView; //7
GradView *gradView; //8
AdminMenueView *adminMenueView; //9
ViewPendingAppsMenue *viewPendingAppsMenue; //10
PendingAppsView *pendingAppsView; //11
AssignMenueView *assignMenueView; //12
AssignSuccessView *assignSuccessView; //13
EditLoginView *editLoginView; //14
EditAppView *editAppView; //15
};
#endif
答案 0 :(得分:1)
在Controller::fillTreeModel(const Glib::ustring &, const Glib::ustring &, const Glib::ustring)
中,如果page
不是“待定”,“分配”或“编辑”之一,则m_Columns
将永远不会被初始化。我没有查看所有代码,因为它相当长,但如果3908326912
无意中(我不确定ModelColumns
是什么),这很可能就是问题。
我建议你有一个默认情况,要么分配默认的回退值,要么抛出异常。