Alright, I'm really bad at asking for help (Lack of details normally), so bare with me here.
Alright, I think I got this linked list thing down. I have a class called LLIST, and a class called NODE.
Like so:
class NODE {
public:
NODE(int gX, int gY);
~NODE();
int getX();
int getY();
void draw();
NODE *next;
private:
SDL_Surface *nodeImg;
SDL_Rect nodeRect;
int x, y;
char *msg;
};
class LLIST {
public:
LLIST() {
head = NULL;
current = NULL;
}
~LLIST();
void insert(int gX, int gY);
void checkList();
private:
NODE *head, *current;
};
Now, in my main I do this to init my llist class, and add a few nodes for testing purposes, and my controls. Basically pushing escape closes the window, and pressing the spacebar spawns a node at the coords.
int main (int argc, char *argv[]) {
bool done;
LLIST *llist;
/* Initialize SDL */
/* Set 640x480 16-bits video mode */
llist = new LLIST();
llist->insert(10, 0);
llist->insert(10, 10);
llist->insert(10, 20);
llist->insert(10, 30);
llist->insert(10, 50);
done = true;
SDL_Event event;
Uint8 *keys;
while (done) {
SDL_PollEvent(&event);
keys = SDL_GetKeyState(NULL);
if(keys[SDLK_ESCAPE] == SDL_PRESSED) {
done = false;
}
if(keys[SDLK_SPACE] == SDL_PRESSED) {
llist->insert(10, 3);
}
llist->checkList();
SDL_Flip(screen);
}
return 0;
}
Alright, the insert function looks like this:
void LLIST::insert(int gX, int gY) {
if(head == NULL) {
head = new NODE(gX, gY);
head->next = NULL;
current = head;
}
else {
current->next = new NODE(gX, gY);
current = current->next;
current->next = NULL;
}
}
Now. My problem appears to be somewhere in the insert function, and in the NODE::NODE(...) function.
See, when I call the first 5 inserts() before the while loop, they work just fine, and draw just fine. But when I press the spacebar and call the same function to do the SAME thing, it crashes.
Here is what the NODE::NODE() function looks like:
NODE::NODE(int gX, int gY) {
nodeImg = SDL_LoadBMP("images/test.bmp");
nodeRect.x = gX;
nodeRect.y = gY;
nodeRect.w = nodeImg->w;
nodeRect.h = nodeImg->h;
}
After logging this baby up the rear, it seems that the NODE::NODE(...) just isn't returning back to the insert() function after new is called. Why? It worked JUST fine for the first few, but when I call it with a keypress, it fails to return. There is no error or anything given by anything. It just closes.
BTW, if anyone knows the tag I need to put the things in the source boxes, that would be helpful to me to help you.
-AfroFire
[edited by - AfroFire on June 28, 2002 7:59:01 PM]
AfroFire | Brin"The only thing that interferes with my learning is my education."-Albert Einstein