Bug Summary

File:client/renderer/r_surface.cpp
Location:line 78, column 2
Description:Access to field 'texnum' results in a dereference of a null pointer (loaded from variable 'image')

Annotated Source Code

1/**
2 * @file
3 * @brief surface-related refresh code
4 */
5
6/*
7Copyright (C) 1997-2001 Id Software, Inc.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24*/
25
26#include "r_local.h"
27#include "r_lightmap.h"
28#include "r_light.h"
29#include "r_error.h"
30#include "r_draw.h"
31
32void R_SetSurfaceBumpMappingParameters (const mBspSurface_t *surf, const image_t *normalMap, const image_t *specularMap)
33{
34 if (!r_state.lighting_enabled)
35 return;
36
37 if (!r_bumpmap->value)
38 return;
39
40 assert(surf)(__builtin_expect(!(surf), 0) ? __assert_rtn(__func__, "src/client/renderer/r_surface.cpp"
, 40, "surf") : (void)0)
;
41
42 if (normalMap && (surf->flags & MSURF_LIGHTMAP2)) {
43 const image_t *image = surf->texinfo->image;
44 R_BindDeluxemapTexture(surf->deluxemap_texnum);
45 R_EnableBumpmap(normalMap);
46 R_EnableSpecularMap(specularMap, true);
47 R_UseMaterial(&image->material);
48 } else {
49 R_EnableBumpmap(NULL__null);
50 R_EnableSpecularMap(NULL__null, false);
51 R_UseMaterial(NULL__null);
52 }
53}
54
55/**
56 * @brief Set the surface state according to surface flags and bind the texture
57 * @sa R_DrawSurfaces
58 */
59static void R_SetSurfaceState (const mBspSurface_t *surf)
60{
61 image_t *image;
62
63 if (r_state.blend_enabled) { /* alpha blend */
14
Taking false branch
64 vec4_t color = {1.0, 1.0, 1.0, 1.0};
65 switch (surf->texinfo->flags & (SURF_BLEND330x00000010 | SURF_BLEND660x00000020)) {
66 case SURF_BLEND330x00000010:
67 color[3] = 0.33;
68 break;
69 case SURF_BLEND660x00000020:
70 color[3] = 0.66;
71 break;
72 }
73
74 R_Color(color);
75 }
76
77 image = surf->texinfo->image;
78 R_BindTexture(image->texnum)R_BindTextureDebug(image->texnum, "src/client/renderer/r_surface.cpp"
, 78, __PRETTY_FUNCTION__)
; /* texture */
15
Within the expansion of the macro 'R_BindTexture':
a
Access to field 'texnum' results in a dereference of a null pointer (loaded from variable 'image')
79
80 if (texunit_lightmapr_state.texunits[1].enabled) { /* lightmap */
81 if (surf->flags & MSURF_LIGHTMAP2)
82 R_BindLightmapTexture(surf->lightmap_texnum);
83 }
84
85 R_SetSurfaceBumpMappingParameters(surf, image->normalmap, image->specularmap);
86
87 R_EnableGlowMap(image->glowmap);
88
89 R_CheckError()R_CheckErrorDebug("src/client/renderer/r_surface.cpp", 89, __PRETTY_FUNCTION__
)
;
90}
91
92/**
93 * @brief Use the vertex, texture and normal arrays to draw a surface
94 * @sa R_DrawSurfaces
95 */
96static inline void R_DrawSurface (const mBspSurface_t *surf)
97{
98 glDrawArrays(GL_TRIANGLE_FAN0x0006, surf->index, surf->numedges);
99
100 refdef.batchCount++;
101
102 if (r_showbox->integer == 2)
103 R_DrawBoundingBox(surf->mins, surf->maxs);
104
105 refdef.brushCount++;
106}
107
108/**
109 * @brief General surface drawing function, that draw the surface chains
110 * @note The needed states for the surfaces must be set before you call this
111 * @sa R_DrawSurface
112 * @sa R_SetSurfaceState
113 */
114void R_DrawSurfaces (const mBspSurfaces_t *surfs)
115{
116 int numSurfaces = surfs->count;
117 mBspSurface_t **surfPtrList = surfs->surfaces;
118 const int frame = r_locals.frame;
119
120 int lastLightMap = 0, lastDeluxeMap = 0;
121 image_t *lastTexture = NULL__null;
122 uint32_t lastFlags = ~0;
123
124 while (numSurfaces--) {
1
Loop condition is true. Entering loop body
4
Loop condition is true. Entering loop body
7
Loop condition is true. Entering loop body
10
Loop condition is true. Entering loop body
125 const mBspSurface_t *surf = *surfPtrList++;
126 mBspTexInfo_t *texInfo;
127 int texFlags;
128 if (surf->frame != frame)
2
Taking false branch
5
Taking false branch
8
Taking false branch
11
Taking false branch
129 continue;
130
131 /** @todo integrate it better with R_SetSurfaceState - maybe cache somewhere in the mBspSurface_t ? */
132 texInfo = surf->texinfo;
133 texFlags = texInfo->flags & (SURF_BLEND330x00000010 | SURF_BLEND660x00000020 | MSURF_LIGHTMAP2); /* should match flags that affect R_SetSurfaceState behavior */
134 if (texInfo->image != lastTexture || surf->lightmap_texnum != lastLightMap || surf->deluxemap_texnum != lastDeluxeMap || texFlags != lastFlags) {
3
Taking false branch
6
Taking false branch
9
Taking false branch
12
Taking true branch
135 lastTexture = texInfo->image;
136 lastLightMap = surf->lightmap_texnum;
137 lastDeluxeMap = surf->deluxemap_texnum;
138 lastFlags = texFlags;
139 R_SetSurfaceState(surf);
13
Calling 'R_SetSurfaceState'
140 }
141
142 R_DrawSurface(surf);
143 }
144
145 /* reset state */
146 if (r_state.active_normalmap)
147 R_EnableBumpmap(NULL__null);
148
149 R_EnableGlowMap(NULL__null);
150
151 R_Color(NULL__null);
152}