My program crashes at times

My program is crashing here is some debugger information. I have highlited in bold where it crashes. What is empty_rep_storage can anyone help me fix this error please?

The program crashes when I press the fed today button a few times and then press the delete button I do this multiple of times and eventually it crashes. I have also highlighted the line of code in bold where it crashes on.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#0 6CB014E7	ZN4Leaf6Record9getColumnESs() (D:\Projects\c++\Leaf\bin\Release\Leaf.dll:??)
#1 00401EBE	[b]_fu14___ZNSs4_Rep20_S_empty_rep_storageE() [/b](D:\Projects\c++\Royal Python Manager\main.cpp:112)
#2 76907694	USER32!CallNextHookEx() (C:\Windows\SysWOW64\user32.dll:??)
#3 7691B943	USER32!AdjustWindowRectEx() (C:\Windows\SysWOW64\user32.dll:??)
#4 7691B7BA	USER32!AdjustWindowRectEx() (C:\Windows\SysWOW64\user32.dll:??)
#5 76920A14	USER32!DrawTextExA() (C:\Windows\SysWOW64\user32.dll:??)
#6 76907694	USER32!CallNextHookEx() (C:\Windows\SysWOW64\user32.dll:??)
#7 76908BAA	USER32!FindWindowA() (C:\Windows\SysWOW64\user32.dll:??)
#8 76939F49	USER32!SoftModalMessageBox() (C:\Windows\SysWOW64\user32.dll:??)
#9 7690F71A	USER32!SendMessageW() (C:\Windows\SysWOW64\user32.dll:??)
#10 7073860D	ImageList_Remove() (C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.9600.16384_none_a9f4965301334e09\comctl32.dll:??)
#11 70738E96	ImageList_Remove() (C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.9600.16384_none_a9f4965301334e09\comctl32.dll:??)
#12 76907694	USER32!CallNextHookEx() (C:\Windows\SysWOW64\user32.dll:??)
#13 76908BAA	USER32!FindWindowA() (C:\Windows\SysWOW64\user32.dll:??)
#14 76908468	USER32!CallNextHookEx() (C:\Windows\SysWOW64\user32.dll:??)
#15 7692D8BB	USER32!IsDialogMessageW() (C:\Windows\SysWOW64\user32.dll:??)
#16 7692D94A	USER32!IsDialogMessageW() (C:\Windows\SysWOW64\user32.dll:??)
#17 7692E02E	USER32!MessageBeep() (C:\Windows\SysWOW64\user32.dll:??)
#18 7692E0D1	USER32!DialogBoxIndirectParamAorW() (C:\Windows\SysWOW64\user32.dll:??)
#19 76954DF3	USER32!DialogBoxParamA() (C:\Windows\SysWOW64\user32.dll:??)
#20 00401B47	WinMain@16(hInstance=0x400000, hPrevInstance=hPrevInstance@entry=0x0, lpCmdLine=<optimized out>, lpCmdLine@entry=0x58349c "", nShowCmd=nShowCmd@entry=10) (D:\Projects\c++\Royal Python Manager\main.cpp:178)
#21 00404ADB	main(argc=1, argv=0x501170, __p__environ=0x501608) (../mingwrt-4.0.3-1-mingw32-src/src/libcrt/crt/main.c:91) 


Here is my sourcecode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <windows.h>
#include <iostream>
#include <commctrl.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <time.h>
#include <Leaf.h>
#include <Vector>
#include "resource.h"
#include "globals.h"
#include "./include/misc.h"
#include "./include/Manager.h"

HINSTANCE hInst;
using namespace std;
int pythonFedId;
std::stringstream ss;
Leaf::Records* records;



/* This function refreshes the list box and adds the data logs from the database*/
void refreshListboxWithDataLogs(HWND hwndDlg, int listBoxId)
{
    // If their are already records loaded then free them
    if (records != NULL)
        records->free();

    HWND listbox = GetDlgItem(hwndDlg, listBoxId);
    // Clear the listbox
    SendMessage(listbox, LB_RESETCONTENT, 0 , 0);

    records = db->getRecords("SELECT * FROM PYTHON_FEEDING WHERE `PYTHON_FED_ID` ORDER BY `FED_DATETIME` DESC");
    if (records == NULL)
        {
            MessageBoxA(0, "Their was a problem trying to retrieve the pythons feeding", "Error", 0);
            exit(1);
        }

    do
    {
        Leaf::Record* r = records->next();
        if (r == NULL)
            continue;
        Leaf::Column* datetime = r->getColumn("FED_DATETIME");
        long d = datetime->data.datal;
        int listItem = (int)SendMessage(listbox, LB_ADDSTRING, 0,
                        (LPARAM) Misc::timeString("Fed: %d/%m/%Y", d).c_str());
        SendMessage(listbox, LB_SETITEMDATA, listItem, (LPARAM) records->curIndex());
    } while(records->moreRecordsAvailable());
}

BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        case WM_INITDIALOG:
        {
            refreshListboxWithDataLogs(hwndDlg, LOGS_LISTBOX);
            Misc::enableDlgItm(hwndDlg, DELETE_BTN, false);
        }
        return TRUE;

        case WM_CLOSE:
        {
            EndDialog(hwndDlg, 0);
        }
        return TRUE;

        case WM_COMMAND:
        {
            switch(LOWORD(wParam))
            {
                case MENU_NEW_ROYAL_PYTHON:
                    DialogBox(hInst, MAKEINTRESOURCE(NEW_PYTHON_DLG), NULL, (DLGPROC)DlgMain);
                break;

                case FED_TODAY_BTN:
                    Manager::snakeFed(30, time(NULL));
                    refreshListboxWithDataLogs(hwndDlg, LOGS_LISTBOX);
                break;

                case DELETE_BTN:
                    int a;
                  //  a = MessageBoxA(0, (LPCSTR)"Are you sure you want to delete this log?", "", MB_YESNO);
               //     if (a == IDYES)
               //     {
                        cout << "Id: " << pythonFedId << endl;
                        ss.str("");
                        ss << "DELETE FROM `PYTHON_FEEDING` WHERE `PYTHON_FED_ID` = " << pythonFedId;
                      db->getRecords(ss.str().c_str());
                        refreshListboxWithDataLogs(hwndDlg, LOGS_LISTBOX);
                        pythonFedId = 0;
                      //  Misc::enableDlgItm(hwndDlg, DELETE_BTN, false);
                  //  }
                    break;


                case LOGS_LISTBOX:
                    switch(HIWORD(wParam))
                    {
                        case LBN_SELCHANGE:
                            int lblItem, recordId;
                            Leaf::Record* selRecord;
                            Leaf::Column* pfid;
                            HWND listbox;
                            listbox = GetDlgItem(hwndDlg, LOGS_LISTBOX);
                            lblItem = (int)SendMessage(listbox, LB_GETCURSEL, 0, 0);
                            recordId = (int)SendMessage(listbox, LB_GETITEMDATA, lblItem, 0);
                            selRecord = records->getRecord(recordId);
                            pfid = selRecord->getColumn("PYTHON_FED_ID");
                            pythonFedId = pfid->data.datai;
                            Misc::enableDlgItm(hwndDlg, DELETE_BTN, true);
                        break;
                    }
                break;
            }
        }
        return TRUE;
    }

    return FALSE;
}

void setupDatabase()
{
    bool error;

    db = new Leaf::LeafDatabase();
   // Open the database
    if(!db->open("database.db"))
    {
        fprintf(stderr, "Can't open database %s", db->getErrMsg());
        exit(1);
    }

    //  Create tables
    error = false;
    if(!db->execute(
                  "CREATE TABLE IF NOT EXISTS `PYTHON_FEEDING`"
                  "("
                  "PYTHON_FED_ID INTEGER PRIMARY KEY AUTOINCREMENT,"
                  "PYTHON_ID INTEGER NOT NULL,"
                  "FED_DATETIME DATETIME NOT NULL"
                  ")"
                  ))
    {
        MessageBoxA(0, "Problem creating table PYTHON_FEEDING", "Database problem", 0);
        error = true;
    }

    if(!db->execute(
                  "CREATE TABLE IF NOT EXISTS `PYTHON_MANAGER_SETTINGS`"
                  "("
                  "PYTHON_MANAGER_SETTING_ID INTEGER PRIMARY KEY NOT NULL,"
                  "SETTING_VALUE NOT NULL"
                  ")"
                  ))
    {
        MessageBoxA(0, "Problem creating table PYTHON_MANAGER_SETTINGS", "Database problem", 0);
        error = true;
    }

    if (error)
        exit(1);
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    setupDatabase();
    if (strcmp(lpCmdLine,"wait") == 0)
    {
        Sleep(10000);
    }
    hInst=hInstance;
    InitCommonControls();
    return DialogBox(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
}
Last edited on
Fixed the issue it turns out if you click on a listbox it will still call LBN_SELCHANGE causing the program to access bad memory as the selected element would be -1.
Last edited on
Topic archived. No new replies allowed.