aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2015-12-02 06:11:35 -0500
committerClyne Sullivan <tullivan99@gmail.com>2015-12-02 06:11:35 -0500
commit67ebafca971ecd4dcfde92bc64a838ba64c16e99 (patch)
tree047de504bb655358ded1f45770c91799aa1c4435 /src
parent8426dc094bf9a0da94c01e46bb34d7d95ba21548 (diff)
segfault fixes
Diffstat (limited to 'src')
-rw-r--r--src/gameplay.cpp5
-rw-r--r--src/inventory.cpp17
-rw-r--r--src/ui.cpp26
-rw-r--r--src/world.cpp29
4 files changed, 56 insertions, 21 deletions
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;i<entity.size();i++){
if(entity[i]==e){
- entity.erase(entity.begin()+i);
switch(e->type){
case STRUCTURET:
for(j=0;j<build.size();j++){
if(build[j]==e){
+ delete build[j];
build.erase(build.begin()+j);
- return;
+ break;
}
}
break;
case NPCT:
for(j=0;j<npc.size();j++){
if(npc[j]==e){
+ delete npc[j];
npc.erase(npc.begin()+j);
- return;
+ break;
}
}
break;
case MOBT:
for(j=0;j<mob.size();j++){
if(mob[j]==e){
+ delete mob[j];
mob.erase(mob.begin()+j);
- return;
+ break;
+ }
+ }
+ break;
+ case OBJECTT:
+ for(j=0;j<object.size();j++){
+ if(object[j]==e){
+ delete object[j];
+ object.erase(object.begin()+j);
+ break;
}
}
break;
}
+ std::cout<<"Killed an entity..."<<std::endl;
+ entity.erase(entity.begin()+i);
return;
}
}
@@ -646,6 +660,8 @@ void World::singleDetect(Entity *e){
*/
i=(e->loc.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);
}