From 67ebafca971ecd4dcfde92bc64a838ba64c16e99 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 2 Dec 2015 06:11:35 -0500 Subject: segfault fixes --- src/gameplay.cpp | 5 +++-- src/inventory.cpp | 17 +++++++++++------ src/ui.cpp | 26 ++++++++++++++++++-------- src/world.cpp | 29 ++++++++++++++++++++++++----- 4 files changed, 56 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/gameplay.cpp b/src/gameplay.cpp index b7eab72..cc9ae6a 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -16,11 +16,12 @@ int giveTestQuest(NPC *speaker){ unsigned char i; ui::dialogBox(speaker->name,":Yes:No","Here, have a quest!"); + ui::waitForDialog(); if(ui::dialogOptChosen == 1){ - - ui::dialogBox(speaker->name,NULL,"Have a good day! :)"); + + ui::dialogBox(speaker->name,"","Have a good day! :)"); ui::waitForDialog(); player->qh.assign("Test"); diff --git a/src/inventory.cpp b/src/inventory.cpp index 28612ae..2af4de3 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -7,6 +7,10 @@ extern Player *player; extern GLuint invUI; +static Item item[5]= { + #include "../config/items.h" +}; + void itemDraw(Player *p,ITEM_ID id); char *getItemTexturePath(ITEM_ID id){ @@ -27,7 +31,7 @@ Item::Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const strcpy(name,n); strcpy(textureLoc,tl); - tex= new Texturec(1,textureLoc); + //tex= new Texturec(1,textureLoc); } Inventory::Inventory(unsigned int s){ @@ -52,13 +56,14 @@ int Inventory::addItem(ITEM_ID id,unsigned char count){ os++; - #ifdef DEBUG - DEBUG_printf("Gave player %u more %s(s)(%d).\n",count,item[id].name,item[id].id); - #endif // DEBUG +#ifdef DEBUG + DEBUG_printf("Gave player %u more %s(s)(ID: %d).\n",count,item[id].name,item[id].id); +#endif // DEBUG - /*#ifdef DEBUG +/*#ifdef DEBUG DEBUG_printf("Failed to add non-existant item with id %u.\n",id); - #endif // DEBUG*/ +#endif // DEBUG*/ + return 0; } diff --git a/src/ui.cpp b/src/ui.cpp index 8d57c36..a37a97c 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -398,20 +398,30 @@ namespace ui { */ while(dialogOptCount){ - if(dialogOptText[dialogOptCount]) + if(dialogOptText[dialogOptCount]){ delete[] dialogOptText[dialogOptCount]; //free(dialogOptText[dialogOptCount]); + dialogOptText[dialogOptCount] = NULL; + } dialogOptCount--; }; + dialogOptChosen=0; dialogOptCount=0; - soptbuf = new char[strlen(opt)+1]; - - sopt=strtok(soptbuf,":"); - while(sopt != NULL){ - dialogOptText[dialogOptCount] = new char[strlen(sopt)+1]; //(char *)malloc(strlen(sopt)); - strcpy(dialogOptText[dialogOptCount++],sopt); - sopt=strtok(NULL,":"); + if(opt){ + + soptbuf = new char[strlen(opt)+1]; + strcpy(soptbuf,opt); + + sopt=strtok(soptbuf,":"); + while(sopt != NULL){ + dialogOptText[dialogOptCount] = new char[strlen(sopt)+1]; //(char *)malloc(strlen(sopt)); + strcpy(dialogOptText[dialogOptCount++],sopt); + sopt=strtok(NULL,":"); + } + + delete[] soptbuf; + } /* diff --git a/src/world.cpp b/src/world.cpp index 8067fe7..c078726 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -586,7 +586,8 @@ LOOP2: } void World::singleDetect(Entity *e){ - unsigned int i,j; + int i; + unsigned int j; /* * Kill any dead entities. @@ -596,33 +597,46 @@ void World::singleDetect(Entity *e){ for(i=0;itype){ case STRUCTURET: for(j=0;jloc.x + e->width / 2 - x_start) / HLINE; + if(i < 0) i=0; + if(i > lineCount-1) i=lineCount-1; /* * If the entity is under the world/line, pop it back to the surface. @@ -672,7 +688,10 @@ void World::singleDetect(Entity *e){ do{ e->loc.x+=.001 * e->vel.x>0?-1:1; + i=(e->loc.x - e->width / 2 - x_start) / HLINE; + if(i < 0){ e->alive = false; return; } + if(i > lineCount-1){ e->alive = false; return; } }while(line[i].y>e->loc.y+ e->height); } -- cgit v1.2.3