Er zijn geen errors als telkens het laatste item uit de lijst wordt verwijderd, vanaf dat er één van de middenste wordt verwijderd(dus alles behalve de eerste en de laatste) zal bij het verwijderen van eender welk ander lijst item een fout worden gegeven.
Qua uitvoering geeft het programma geen problemen, want de items worden wel degelijk uit de lijst verwijderd. Ik vermoed dat het opkuisen van de linked list items (bij het verwijderen van een item) niet wordt gedaan zoals het moet... (ja, weeral die kl*** delete ws).
De foutmelding is:
De leesbewerking "read" op het geheugen is mislukt
Nota: Nieuwe items worden vooraan in de lijst geplaatst.
Qua uitvoering geeft het programma geen problemen, want de items worden wel degelijk uit de lijst verwijderd. Ik vermoed dat het opkuisen van de linked list items (bij het verwijderen van een item) niet wordt gedaan zoals het moet... (ja, weeral die kl*** delete ws).
De foutmelding is:
De leesbewerking "read" op het geheugen is mislukt
Nota: Nieuwe items worden vooraan in de lijst geplaatst.
C++:
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
| struct LL_SOCKETS { SOCKET sock; // client socket int id; // player server ID int score; // current player score int ping; // current ping float pingStartTime; // start time of last ping poll char* nick; // player nickname LL_SOCKETS *next; // pointer to next list item }; extern LL_SOCKETS *ll_tex_start; // start pointer of list LL_SOCKETS *ll_sock_start = NULL; int connectedUsers = 0; // counts amount of connected users //add an item in the list (WERKT PERFECT!) int LL_Sockets_Add(SOCKET insocket) { static int idCounter; idCounter++; LL_SOCKETS *new_item = new LL_SOCKETS; // make a new list item new_item->sock = insocket; new_item->id = idCounter; // define the new item new_item->nick = "undefined"; new_item->pingStartTime = 0.0f; new_item->ping = 0; new_item->next = ll_sock_start; // push the list a bit further to the right ll_sock_start = new_item; // set the start pointer to the this item Cns_Addline("[socket added to list]"); connectedUsers++; return idCounter; } // IN DEZE FUNCTIE ZIT DE FOUT: // remove a socket from the linked list void LL_Sockets_Remove(SOCKET insock) { LL_SOCKETS *ll_sock_current = NULL; // current read pointer LL_SOCKETS *ll_sock_previous = NULL; // previous read pointer ll_sock_previous = ll_sock_start; // set previous read pointer to start item ll_sock_current = ll_sock_start->next; // set current read pointer to the second item LL_Sockets_Viewlist(); // view the socket list (details of all clients) if (ll_sock_start->sock == insock) // socket to delete is first socket in list { if (ll_sock_start->next) // there is a list item after this list { Cns_Addline("FIRST CLIENT DISCONNECTS, THERE IS A SECOND CLIENT AFTER 1ST"); delete(ll_sock_start); ll_sock_start = new LL_SOCKETS; ll_sock_start = ll_sock_start->next; } else { // first (and only) list item Cns_Addline("FIRST CLIENT DISCONNECTS, ONLY CLIENT IN LIST"); delete(ll_sock_start); ll_sock_start = new LL_SOCKETS; ll_sock_start = NULL; } connectedUsers--; return; } else { // look further in list Cns_Addline("CLIENT DISCONNECTS, NOT FIRST CLIENT IN LIST"); while (ll_sock_current) { if (ll_sock_current->sock == insock) { if (ll_sock_current->next != NULL) // item to be removed is NOT the last list item in the list { Cns_Addline("TYPE 1"); ll_sock_previous->next = ll_sock_current->next; delete(ll_sock_current); } else { // item to be removed is last list item Cns_Addline("TYPE 2"); ll_sock_previous->next = NULL; delete(ll_sock_current); } connectedUsers--; return; } ll_sock_previous = ll_sock_current; // store current socket in 'previous socket' pointer ll_sock_current = ll_sock_current->next; // read next socket } } } |