Item being skipped

MB is a message box and for some reason it is not being reached, I've got to go to work in a minute so I figured maybe someone can spot the problem while I'm there. This is the File and code:
1
2
3
4
5
6
[Final-Fantasy-10]
;Final Fantasy 10;uk;SLES-00000;0000
Spira
[Final-Fantasy-12]
;Final Fantasy 12;uk;SLES-51154;0001
Ivalice

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
void ME::DBLoad(void) {
	DBSet();
	wxString s, t, t1, t2, t3;
	wxStringTokenizer st; dl = 0;
	DB->CollapseAndReset(rdi); bool u = false;
	DBI* cv = new DBI; u8 m = 0, m2;
	for (t = dbf.GetFirstLine(); !dbf.Eof(); t = dbf.GetNextLine()) {
		s = t.SubString(0, 0);
		switch (m) {
		case 1: m2 = 0;
			st.SetString(t, wxT(";"));
			while (st.HasMoreTokens()) {
				s = st.GetNextToken();
				if (m2 == 1) { t1 = s; }
				if (m2 == 3) { cv->afs = s; }
				if (m2 == 4) { cv->afi = getHEX(s); }
				m2++;
			} m = 2; break;
		case 2:
			if (s.Cmp(wxT("[")) == 0) {
				t3 = t.SubString(1, t.length() - 2);
				DBAdd(t1, cv);
				cv = new DBI;
				cv->afp = t3;
				t3.Clear();
				m = 1;
			} else { cv->afn += t; }
			break;
		default:
			if (s.Cmp(wxT("[")) == 0) {
				t3 = t.SubString(1, t.length() - 2);
				m = 1; u = true;
			}
		}
	} if (u == true) { DBAdd(t1, cv); MB(cv->afp, t1); }
	wxTreeItemIdValue v;
	rdi = DBRoot();
	di = DB->GetFirstChild(rdi, v);
	DB->SelectItem(di);
}
*sigh* DBI* cv = new DBI; is leaking.
You should use meaningful names for your variables.

IIRC the loop will execute the default case until a line starting with '[' appears. Then it will never be executed again.
So you may want to divide it into 2 loops.

If the message box is not reached, then s.Cmp(wxT("[")) == 0 never holds. Check its value.
Last edited on
1. DBI is a subclass of wxTreeItemData so needs a new value for the next item, unless using DBI* for my function's argument means the data has been passed as a value and not a reference.

2. The name is meaningful - DataBase Item, DBI.

3. The default case is deliberate, it prevents processing of data until first item is found, from then on it adds the previous item to the list before overriding the variables with the new item.

4. wxT("[") is fine because it produces the other item/s just not the final item

5. The 2 loop thing is a good idea though, would prevent creating a useless DBI instance

Thank you anyway, I will at least add else { delete cv; } to my if statement to prevent the leaking issue, the if statement was added because the final item would never be added otherwise. It has also just occurred to me that will need to code a conversion of the "[" character for the notes (cv->afn) so don't bother mentioning that.
Last edited on
After modding DBAdd() to except an optional third parameter to prevent it selecting an item it got through to the message box, which means there is something wrong with how I pass the DBI* argument. I'll have to try copying the style of code from another tree load function. I will create a DBCopy() function to copy info from the argument to the internal DBI I will make DBAdd() create.

Edit: Same problem but weirder, get's to DBAdd() (had MB in that) but the last item doesn't show in the list, any ideas?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void ME::DBAdd(void) {
	DBI* cv = new DBI;
	wxString s;
	s.Printf(wxT("New Hack Tree %i"), dl);
	cv->afp = s;
	cv->afn = wxT("Notes");
	DBAdd(s, cv);
	delete cv;
}
void ME::DBAdd(wxString s, DBI* cv) {
	DBI* t = new DBI;
	t = DBCopy(cv, t);
	di = DB->AppendItem(rdi, s, -1, -1, t);
	DB->SelectItem(di); dl++;
}

Had something to do with the root id, it apparently changes after it gains children - Found this out by changing the code to
1
2
3
4
5
6
7
void ME::DBAdd(wxString s, DBI* cv) {
	DBI* t = new DBI;
	t = DBCopy(cv, t);
	di = DB->AppendItem(rdi, s, -1, -1, t);
	rdi = DBRoot(di);
	DB->SelectItem(di); dl++;
}
rdi = DBRoot(di); is an annoying overhead but given the context and speed of today's computers it's unlikely to ever be noticed by the user.
Last edited on
Topic archived. No new replies allowed.