Skip to content

Commit bcdfc3d

Browse files
author
nitrocaster
committed
Fix bad mem_fill32 replacement.
1 parent 705f2da commit bcdfc3d

File tree

4 files changed

+153
-145
lines changed

4 files changed

+153
-145
lines changed

src/Layers/xrRender/occRasterizer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ occRasterizer::~occRasterizer ()
6565

6666
void occRasterizer::clear ()
6767
{
68-
u32 size = occ_dim*occ_dim;
68+
u32 size = occ_dim*occ_dim*sizeof(float);
6969
float f = 1.f;
70-
memset (bufFrame,0,size);
71-
memset (bufDepth,*LPDWORD(&f),size);
70+
MemFill32(bufFrame,0,size);
71+
MemFill32(bufDepth,*LPDWORD(&f),size);
7272
}
7373

7474
IC BOOL shared(occTri* T1, occTri* T2)

src/editors/ECore/Editor/EditMeshIO.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88
#include "EditMesh.h"
99
#include "EditObject.h"
1010

11-
#define EMESH_CURRENT_VERSION 0x0011
11+
#define EMESH_CURRENT_VERSION 0x0011
1212
//----------------------------------------------------
13-
#define EMESH_CHUNK_VERSION 0x1000
14-
#define EMESH_CHUNK_MESHNAME 0x1001
15-
#define EMESH_CHUNK_FLAGS 0x1002
16-
#define EMESH_CHUNK_NOT_USED_0 0x1003
17-
#define EMESH_CHUNK_BBOX 0x1004
18-
#define EMESH_CHUNK_VERTS 0x1005
19-
#define EMESH_CHUNK_FACES 0x1006
20-
#define EMESH_CHUNK_VMAPS_0 0x1007
21-
#define EMESH_CHUNK_VMREFS 0x1008
22-
#define EMESH_CHUNK_SFACE 0x1009
23-
#define EMESH_CHUNK_BOP 0x1010
24-
#define EMESH_CHUNK_VMAPS_1 0x1011
25-
#define EMESH_CHUNK_VMAPS_2 0x1012
26-
#define EMESH_CHUNK_SG 0x1013
13+
#define EMESH_CHUNK_VERSION 0x1000
14+
#define EMESH_CHUNK_MESHNAME 0x1001
15+
#define EMESH_CHUNK_FLAGS 0x1002
16+
#define EMESH_CHUNK_NOT_USED_0 0x1003
17+
#define EMESH_CHUNK_BBOX 0x1004
18+
#define EMESH_CHUNK_VERTS 0x1005
19+
#define EMESH_CHUNK_FACES 0x1006
20+
#define EMESH_CHUNK_VMAPS_0 0x1007
21+
#define EMESH_CHUNK_VMREFS 0x1008
22+
#define EMESH_CHUNK_SFACE 0x1009
23+
#define EMESH_CHUNK_BOP 0x1010
24+
#define EMESH_CHUNK_VMAPS_1 0x1011
25+
#define EMESH_CHUNK_VMAPS_2 0x1012
26+
#define EMESH_CHUNK_SG 0x1013
2727

2828
void CEditableMesh::SaveMesh(IWriter &F)
2929
{
@@ -135,7 +135,7 @@ bool CEditableMesh::LoadMesh(IReader &F)
135135
F.r(m_Faces, m_FaceCount*sizeof(st_Face));
136136

137137
m_SmoothGroups = xr_alloc<u32>(m_FaceCount);
138-
memset(m_SmoothGroups, m_Flags.is(flSGMask) ? 0 : u32(-1), m_FaceCount);
138+
MemFill32(m_SmoothGroups, m_Flags.is(flSGMask) ? 0 : u32(-1), m_FaceCount);
139139
u32 sg_chunk_size = F.find_chunk(EMESH_CHUNK_SG);
140140
if (sg_chunk_size)
141141
{
@@ -226,17 +226,17 @@ bool CEditableMesh::LoadMesh(IReader &F)
226226
#ifdef _EDITOR
227227
if (!EPrefs->object_flags.is(epoDeffLoadRB))
228228
{
229-
GenerateFNormals ();
230-
GenerateAdjacency ();
231-
GenerateVNormals (0);
232-
GenerateRenderBuffers();
233-
UnloadFNormals ();
234-
UnloadAdjacency ();
235-
UnloadVNormals ();
229+
GenerateFNormals ();
230+
GenerateAdjacency ();
231+
GenerateVNormals (0);
232+
GenerateRenderBuffers();
233+
UnloadFNormals ();
234+
UnloadAdjacency ();
235+
UnloadVNormals ();
236236
}
237237

238238
if (!EPrefs->object_flags.is(epoDeffLoadCF))
239-
GenerateCFModel();
239+
GenerateCFModel();
240240
#endif
241241
OptimizeMesh(false);
242242
RebuildVMaps();

src/xrCore/_std_extensions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,14 @@ inline int xr_strcat(char(&destination)[count], LPCSTR source)
286286
}
287287
#endif // #ifndef _EDITOR
288288

289+
inline void MemFill32(void *dst, u32 value, size_t dstSize)
290+
{
291+
u32 *ptr = static_cast<u32 *>(dst);
292+
u32 *end = ptr+dstSize;
293+
while (ptr!=end)
294+
*ptr++ = value;
295+
}
296+
289297
XRCORE_API char* timestamp(string64& dest);
290298

291299
extern XRCORE_API u32 crc32(const void* P, u32 len);

src/xrSound/SoundRender_Cache.cpp

Lines changed: 118 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -3,159 +3,159 @@
33

44
#include ".\soundrender_cache.h"
55

6-
CSoundRender_Cache::CSoundRender_Cache ()
6+
CSoundRender_Cache::CSoundRender_Cache ()
77
{
8-
data = NULL;
9-
c_storage = NULL;
10-
c_begin = NULL;
11-
c_end = NULL;
12-
_total = 0;
13-
_line = 0;
14-
_count = 0;
8+
data = NULL;
9+
c_storage = NULL;
10+
c_begin = NULL;
11+
c_end = NULL;
12+
_total = 0;
13+
_line = 0;
14+
_count = 0;
1515
}
1616

17-
CSoundRender_Cache::~CSoundRender_Cache ()
17+
CSoundRender_Cache::~CSoundRender_Cache ()
1818
{
1919
}
2020

2121

22-
void CSoundRender_Cache::move2top (cache_line* line)
22+
void CSoundRender_Cache::move2top (cache_line* line)
2323
{
24-
VERIFY (line);
25-
if (line==c_begin) return; // already at top
24+
VERIFY (line);
25+
if (line==c_begin) return; // already at top
2626

27-
// track end
28-
if (line==c_end) c_end = c_end->prev;
27+
// track end
28+
if (line==c_end) c_end = c_end->prev;
2929

30-
// cut
31-
cache_line* prev = line->prev;
32-
cache_line* next = line->next;
33-
if (prev) prev->next = next;
34-
if (next) next->prev = prev;
30+
// cut
31+
cache_line* prev = line->prev;
32+
cache_line* next = line->next;
33+
if (prev) prev->next = next;
34+
if (next) next->prev = prev;
3535

36-
// register at top
37-
line->prev = NULL;
38-
line->next = c_begin;
36+
// register at top
37+
line->prev = NULL;
38+
line->next = c_begin;
3939

40-
// track begin
41-
c_begin->prev = line;
42-
c_begin = line;
40+
// track begin
41+
c_begin->prev = line;
42+
c_begin = line;
4343

44-
// internal verify
45-
VERIFY (c_begin->prev == NULL);
46-
VERIFY (c_end->next == NULL);
44+
// internal verify
45+
VERIFY (c_begin->prev == NULL);
46+
VERIFY (c_end->next == NULL);
4747
}
4848

49-
BOOL CSoundRender_Cache::request (cache_cat& cat, u32 id)
49+
BOOL CSoundRender_Cache::request (cache_cat& cat, u32 id)
5050
{
51-
// 1. check if cached version available
52-
id %= cat.size;
53-
//. R_ASSERT (id<cat.size);
54-
u16& cptr = cat.table[id];
55-
if (CAT_FREE != cptr) {
56-
// cache line exists - change it's priority and return
57-
_stat_hit ++;
58-
cache_line* L = c_storage + cptr;
59-
move2top (L);
60-
return FALSE;
61-
}
62-
63-
// 2. purge oldest item + move it to top
64-
_stat_miss ++;
65-
move2top (c_end);
66-
if (c_begin->loopback) {
67-
*c_begin->loopback = CAT_FREE;
68-
c_begin->loopback = NULL;
69-
}
70-
71-
// 3. associate
72-
cptr = c_begin->id;
73-
c_begin->loopback = &cptr;
74-
75-
// 4. fill with data
76-
return TRUE;
51+
// 1. check if cached version available
52+
id %= cat.size;
53+
//. R_ASSERT (id<cat.size);
54+
u16& cptr = cat.table[id];
55+
if (CAT_FREE != cptr) {
56+
// cache line exists - change it's priority and return
57+
_stat_hit ++;
58+
cache_line* L = c_storage + cptr;
59+
move2top (L);
60+
return FALSE;
61+
}
62+
63+
// 2. purge oldest item + move it to top
64+
_stat_miss ++;
65+
move2top (c_end);
66+
if (c_begin->loopback) {
67+
*c_begin->loopback = CAT_FREE;
68+
c_begin->loopback = NULL;
69+
}
70+
71+
// 3. associate
72+
cptr = c_begin->id;
73+
c_begin->loopback = &cptr;
74+
75+
// 4. fill with data
76+
return TRUE;
7777
}
7878

79-
void CSoundRender_Cache::initialize (u32 _total_kb_approx, u32 bytes_per_line)
79+
void CSoundRender_Cache::initialize (u32 _total_kb_approx, u32 bytes_per_line)
8080
{
81-
// use twice the requisted memory (to avoid bad configs)
82-
_total_kb_approx *= 2;
83-
84-
// calc
85-
_line = bytes_per_line;
86-
_count = ((_total_kb_approx*1024)/bytes_per_line + 1);
87-
_total = _count*_line;
88-
R_ASSERT (_count<CAT_FREE);
89-
Msg ("* sound : cache: %d kb, %d lines, %d bpl",_total/1024,_count,_line);
90-
91-
// alloc structs
92-
data = xr_alloc<u8> (_total);
93-
c_storage = xr_alloc<cache_line> (_count);
94-
95-
// format
96-
format ();
81+
// use twice the requisted memory (to avoid bad configs)
82+
_total_kb_approx *= 2;
83+
84+
// calc
85+
_line = bytes_per_line;
86+
_count = ((_total_kb_approx*1024)/bytes_per_line + 1);
87+
_total = _count*_line;
88+
R_ASSERT (_count<CAT_FREE);
89+
Msg ("* sound : cache: %d kb, %d lines, %d bpl",_total/1024,_count,_line);
90+
91+
// alloc structs
92+
data = xr_alloc<u8> (_total);
93+
c_storage = xr_alloc<cache_line> (_count);
94+
95+
// format
96+
format ();
9797
}
9898

99-
void CSoundRender_Cache::disconnect ()
99+
void CSoundRender_Cache::disconnect ()
100100
{
101-
// disconnect from CATs
102-
for (u32 it=0; it<_count; it++)
103-
{
104-
cache_line* L = c_storage+it;
105-
if (L->loopback) {
106-
*L->loopback = CAT_FREE;
107-
L->loopback = NULL;
108-
}
109-
}
101+
// disconnect from CATs
102+
for (u32 it=0; it<_count; it++)
103+
{
104+
cache_line* L = c_storage+it;
105+
if (L->loopback) {
106+
*L->loopback = CAT_FREE;
107+
L->loopback = NULL;
108+
}
109+
}
110110
}
111111

112-
void CSoundRender_Cache::format ()
112+
void CSoundRender_Cache::format ()
113113
{
114-
// format structs
115-
for (u32 it=0; it<_count; it++)
116-
{
117-
cache_line* L = c_storage+it;
118-
L->prev = (0==it) ? NULL : c_storage+it-1;
119-
L->next = ((_count-1) == it) ? NULL : c_storage+it+1;
120-
L->data = data + it*_line;
121-
L->loopback = NULL;
122-
L->id = u16 (it);
123-
}
124-
125-
// start-end
126-
c_begin = c_storage + 0;
127-
c_end = c_storage + _count - 1;
114+
// format structs
115+
for (u32 it=0; it<_count; it++)
116+
{
117+
cache_line* L = c_storage+it;
118+
L->prev = (0==it) ? NULL : c_storage+it-1;
119+
L->next = ((_count-1) == it) ? NULL : c_storage+it+1;
120+
L->data = data + it*_line;
121+
L->loopback = NULL;
122+
L->id = u16 (it);
123+
}
124+
125+
// start-end
126+
c_begin = c_storage + 0;
127+
c_end = c_storage + _count - 1;
128128
}
129129

130-
void CSoundRender_Cache::purge ()
130+
void CSoundRender_Cache::purge ()
131131
{
132-
disconnect (); // disconnect from CATs
133-
format (); // format
132+
disconnect (); // disconnect from CATs
133+
format (); // format
134134
}
135135

136-
void CSoundRender_Cache::destroy ()
136+
void CSoundRender_Cache::destroy ()
137137
{
138-
disconnect ();
139-
xr_free (data);
140-
xr_free (c_storage);
141-
c_begin = NULL;
142-
c_end = NULL;
143-
_total = 0;
144-
_line = 0;
145-
_count = 0;
138+
disconnect ();
139+
xr_free (data);
140+
xr_free (c_storage);
141+
c_begin = NULL;
142+
c_end = NULL;
143+
_total = 0;
144+
_line = 0;
145+
_count = 0;
146146
}
147147

148-
void CSoundRender_Cache::cat_create (cache_cat& cat, u32 bytes)
148+
void CSoundRender_Cache::cat_create (cache_cat& cat, u32 bytes)
149149
{
150-
cat.size = bytes / _line;
151-
if (bytes%_line) cat.size += 1;
152-
u32 allocsize = (cat.size&1)?cat.size+1:cat.size;
153-
cat.table = xr_alloc<u16>(allocsize);
154-
memset (cat.table,0xffffffff,allocsize/2);
150+
cat.size = bytes / _line;
151+
if (bytes%_line) cat.size += 1;
152+
u32 allocsize = (cat.size&1)?cat.size+1:cat.size;
153+
cat.table = xr_alloc<u16>(allocsize);
154+
MemFill32(cat.table,0xffffffff,allocsize/2);
155155
}
156156

157-
void CSoundRender_Cache::cat_destroy (cache_cat& cat)
157+
void CSoundRender_Cache::cat_destroy (cache_cat& cat)
158158
{
159-
xr_free (cat.table);
160-
cat.size = 0;
159+
xr_free (cat.table);
160+
cat.size = 0;
161161
}

0 commit comments

Comments
 (0)