0

これは宿題です

ねえ、割り当てにGtkmmを使用していますが、すべてうまくいっていますが、TreeViewを埋めるために使用する関数で奇妙な問題が発生し、エラーが発生します

(out:21185): GLib-ERROR **: /build/buildd/glib2.0-2.32.3/./glib/gmem.c:408: オーバーフロー割り当て 3908326912*4 バイト トレース/ブレークポイント トラップ (コア ダンプ)

ただし、奇妙な部分は、この関数を 3 つの個別の TreeView に使用していることです。これは、私が書いた最新のものだけであり、このエラーが発生します。

私は問題をラインに切り分けました

*m_refTreeModel = Gtk::ListStore::create((*m_columns));

これがどのように起こっているのかについてのアイデアはありますか? 私のプログラムはかなり大きいので、これに関連するすべてのソース コードを表示するのは難しいでしょう。ただし、この行が含まれている関数は次のとおりです

コントローラ.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
4

1 に答える 1

1

ではController::fillTreeModel(const Glib::ustring &, const Glib::ustring &, const Glib::ustring)pageが「保留中」、「割り当て」、または「編集」のいずれでもない場合、m_Columns決して初期化されません。かなり長いので、すべてのコードを調べたわけではありませんが、これ3908326912が意図しない場合の問題である可能性が最も高いです (ただし、 aModelColumnsが何であるかはわかりません)。

デフォルトのフォールバック値を割り当てるか、例外をスローするデフォルトのケースがあることをお勧めします。

于 2013-03-22T03:15:44.400 に答える