Browse Source

No longer segfaulting walking Yvel.tr2

Thomas Buck 10 years ago
parent
commit
1aaa6ceef0
1 changed files with 19 additions and 18 deletions
  1. 19
    18
      src/World.cpp

+ 19
- 18
src/World.cpp View File

122
     sector_t * s;
122
     sector_t * s;
123
     int sector;
123
     int sector;
124
 
124
 
125
+    assert(room >= 0);
126
+    assert(floor != NULL);
127
+    assert(ceiling != NULL);
128
+
125
     r = mRooms[room];
129
     r = mRooms[room];
126
 
130
 
127
     if (!r)
131
     if (!r)
145
 }
149
 }
146
 
150
 
147
 
151
 
148
-int World::getSector(int room, float x, float z)
149
-{
152
+int World::getSector(int room, float x, float z) {
150
     int sector;
153
     int sector;
151
     room_mesh_t *r;
154
     room_mesh_t *r;
152
 
155
 
156
+    if ((room < 0) || (room >= mRooms.size()))
157
+        return -1;
158
+
153
     r = mRooms[room];
159
     r = mRooms[room];
154
 
160
 
155
     if (!r)
161
     if (!r)
156
-    {
157
         return -1;
162
         return -1;
158
-    }
159
 
163
 
160
     sector = (((((int)x - (int)r->pos[0]) / 1024) * r->numZSectors) +
164
     sector = (((((int)x - (int)r->pos[0]) / 1024) * r->numZSectors) +
161
             (((int)z - (int)r->pos[2]) / 1024));
165
             (((int)z - (int)r->pos[2]) / 1024));
162
 
166
 
163
     if (sector < 0)
167
     if (sector < 0)
164
-    {
165
         return -1;
168
         return -1;
166
-    }
167
 
169
 
168
     return sector;
170
     return sector;
169
 }
171
 }
170
 
172
 
171
 
173
 
172
-unsigned int World::getRoomInfo(int room)
173
-{
174
+unsigned int World::getRoomInfo(int room) {
174
     room_mesh_t *r;
175
     room_mesh_t *r;
175
 
176
 
177
+    if ((room >= mRooms.size()) || (room < 0))
178
+        return 0;
176
 
179
 
177
     r = mRooms[room];
180
     r = mRooms[room];
178
 
181
 
179
     if (!r)
182
     if (!r)
180
-    {
181
         return 0;
183
         return 0;
182
-    }
183
 
184
 
184
     return r->flags;
185
     return r->flags;
185
 }
186
 }
186
 
187
 
187
 
188
 
188
-bool World::isWall(int room, int sector)
189
-{
189
+bool World::isWall(int room, int sector) {
190
     room_mesh_t *r;
190
     room_mesh_t *r;
191
     sector_t *sect;
191
     sector_t *sect;
192
 
192
 
193
+    if ((room >= mRooms.size()) || (room < 0))
194
+        return true;
193
 
195
 
194
     r = mRooms[room];
196
     r = mRooms[room];
195
 
197
 
196
-    if (!r)
197
-    {
198
+    if ((!r) || (sector >= r->sectors.size()) || (sector < 0))
198
         return true;
199
         return true;
199
-    }
200
 
200
 
201
     sect = r->sectors[sector];
201
     sect = r->sectors[sector];
202
 
202
 
203
     if (!sect)
203
     if (!sect)
204
-    {
205
         return true;
204
         return true;
206
-    }
207
 
205
 
208
-    return ((sector > 0) && sect->wall);
206
+    return ((sector > 0) && sect->wall); //! \fixme is (sector > 0) correct??
209
 }
207
 }
210
 
208
 
211
 
209
 
465
         if (room > -1)
463
         if (room > -1)
466
         {
464
         {
467
             printf("Crossing from room %i to %i\n", e->room, room);
465
             printf("Crossing from room %i to %i\n", e->room, room);
466
+        } else {
467
+            //! \fixme mRooms, sectors, ... are now std::vector, but often upper bound checks are missing
468
+            return;
468
         }
469
         }
469
     }
470
     }
470
 
471
 

Loading…
Cancel
Save