fix some bugs found by scan-build

This commit is contained in:
Andrei Alexeyev 2019-01-25 02:52:00 +02:00
parent 9af300d4df
commit ce2e92e9f8
No known key found for this signature in database
GPG key ID: 363707CD4C7FE8A4
4 changed files with 47 additions and 13 deletions

View file

@ -126,6 +126,7 @@ static GLTextureFormatTuple* prepare_pixmap(Texture *tex, const Pixmap *px_in, P
static void gl33_texture_set(Texture *tex, uint mipmap, const Pixmap *image) {
assert(mipmap < tex->params.mipmaps);
assert(image != NULL);
Pixmap pix;
GLTextureFormatTuple *fmt = prepare_pixmap(tex, image, &pix);
@ -272,8 +273,24 @@ void gl33_texture_set_wrap(Texture *tex, TextureWrapMode ws, TextureWrapMode wt)
}
void gl33_texture_invalidate(Texture *tex) {
gl33_bind_texture(tex, false);
gl33_sync_texunit(tex->binding_unit, false, true);
for(uint i = 0; i < tex->params.mipmaps; ++i) {
gl33_texture_set(tex, i, NULL);
uint width, height;
gl33_texture_get_size(tex, i, &width, &height);
glTexImage2D(
GL_TEXTURE_2D,
i,
tex->type_info->internal_fmt,
width,
height,
0,
tex->type_info->primary_external_format.gl_fmt,
tex->type_info->primary_external_format.gl_type,
NULL
);
}
}

View file

@ -34,7 +34,7 @@ ResourceHandler model_res_handler = {
},
};
static void parse_obj(const char *filename, ObjFileData *data);
static bool parse_obj(const char *filename, ObjFileData *data);
static void free_obj(ObjFileData *data);
char* model_path(const char *name) {
@ -55,7 +55,10 @@ void* load_model_begin(const char *path, uint flags) {
ObjFileData *data = malloc(sizeof(ObjFileData));
GenericModelVertex *verts;
parse_obj(path, data);
if(!parse_obj(path, data)) {
free(data);
return NULL;
}
uint *indices = calloc(data->icount, sizeof(uint));
uint icount = data->icount;
@ -146,12 +149,12 @@ static void free_obj(ObjFileData *data) {
free(data->indices);
}
static void parse_obj(const char *filename, ObjFileData *data) {
static bool parse_obj(const char *filename, ObjFileData *data) {
SDL_RWops *rw = vfs_open(filename, VFS_MODE_READ);
if(!rw) {
log_warn("VFS error: %s", vfs_get_error());
return;
return false;
}
char line[256], *save;
@ -227,8 +230,10 @@ static void parse_obj(const char *filename, ObjFileData *data) {
ibuf[1] = 0;
}
if(jj == 0 || jj > 3 || segment[0] == '/')
log_fatal("OBJ file '%s:%d': Parsing error: Corrupt face definition", filename,linen);
if(jj == 0 || jj > 3 || segment[0] == '/') {
log_warn("OBJ file '%s:%d': Parsing error: Corrupt face definition", filename, linen);
goto fail;
}
data->indices = realloc(data->indices, sizeof(ivec3_noalign)*(++data->icount));
memcpy(data->indices[data->icount-1], ibuf, sizeof(ivec3_noalign));
@ -237,15 +242,27 @@ static void parse_obj(const char *filename, ObjFileData *data) {
if(data->fverts == 0)
data->fverts = j;
if(data->fverts != j)
log_fatal("OBJ file '%s:%d': Parsing error: face vertex count must stay the same in the whole file", filename, linen);
if(data->fverts != j) {
log_warn("OBJ file '%s:%d': Parsing error: face vertex count must stay the same in the whole file", filename, linen);
goto fail;
}
if(data->fverts != 3)
log_fatal("OBJ file '%s:%d': Parsing error: face vertex count must be 3", filename, linen);
if(data->fverts != 3) {
log_warn("OBJ file '%s:%d': Parsing error: face vertex count must be 3", filename, linen);
goto fail;
}
}
}
SDL_RWclose(rw);
return true;
fail:
SDL_RWclose(rw);
free(data->indices);
free(data->normals);
free(data->xs);
return false;
}
Model* get_model(const char *name) {

View file

@ -342,8 +342,8 @@ static void* load_texture_begin(const char *path, uint flags) {
}
if(!pixmap_load_file(source, &ld.pixmap)) {
free(source_allocated);
log_warn("%s: couldn't load texture image", source);
free(source_allocated);
return NULL;
}

View file

@ -527,7 +527,7 @@ static void draw_spellbg(int t) {
}
static inline bool should_draw_stage_bg(void) {
if(!global.boss)
if(!global.boss || !global.boss->current)
return true;
int render_delay = 1.25*ATTACK_START_DELAY; // hand tuned... not ideal