@@ -151,6 +151,71 @@ fn check_standard_material_churn_leak() {
151
151
}
152
152
}
153
153
154
+ #[ ignore = "FIXME Failing test" ]
155
+ #[ test]
156
+ fn check_mesh_churn_insert_leak ( ) {
157
+ let mut app = App :: new ( ) ;
158
+ app. add_plugins ( (
159
+ DefaultPlugins
160
+ . build ( )
161
+ . disable :: < AudioPlugin > ( )
162
+ . disable :: < WinitPlugin > ( )
163
+ . disable :: < WindowPlugin > ( ) ,
164
+ LogDiagnosticsPlugin {
165
+ wait_duration : Duration :: ZERO ,
166
+ ..Default :: default ( )
167
+ } ,
168
+ RenderAssetDiagnosticPlugin :: < RenderMesh > :: new ( " meshes" ) ,
169
+ MeshAllocatorDiagnosticPlugin ,
170
+ ) )
171
+ . add_systems ( Startup , mesh_setup)
172
+ . add_systems (
173
+ Update ,
174
+ ( churn_using_insert :: < Mesh > , crash_on_mesh_leak_detection) ,
175
+ ) ;
176
+
177
+ app. finish ( ) ;
178
+ app. cleanup ( ) ;
179
+
180
+ for _ in 0 ..100 {
181
+ app. update ( ) ;
182
+ }
183
+ }
184
+
185
+ #[ ignore = "FIXME Failing test" ]
186
+ #[ test]
187
+ fn check_standard_material_churn_insert_leak ( ) {
188
+ let mut app = App :: new ( ) ;
189
+ app. add_plugins ( (
190
+ DefaultPlugins
191
+ . build ( )
192
+ . disable :: < AudioPlugin > ( )
193
+ . disable :: < WinitPlugin > ( )
194
+ . disable :: < WindowPlugin > ( ) ,
195
+ LogDiagnosticsPlugin {
196
+ wait_duration : Duration :: ZERO ,
197
+ ..Default :: default ( )
198
+ } ,
199
+ RenderAssetDiagnosticPlugin :: < PreparedMaterial < StandardMaterial > > :: new ( " materials" ) ,
200
+ MaterialAllocatorDiagnosticPlugin :: < StandardMaterial > :: default ( ) ,
201
+ ) )
202
+ . add_systems ( Startup , mesh_setup)
203
+ . add_systems (
204
+ Update ,
205
+ (
206
+ churn_using_insert :: < StandardMaterial > ,
207
+ crash_on_material_leak_detection :: < StandardMaterial > ,
208
+ ) ,
209
+ ) ;
210
+
211
+ app. finish ( ) ;
212
+ app. cleanup ( ) ;
213
+
214
+ for _ in 0 ..100 {
215
+ app. update ( ) ;
216
+ }
217
+ }
218
+
154
219
#[ derive( Resource ) ]
155
220
struct Leaker < A : Asset > ( Vec < Handle < A > > ) ;
156
221
@@ -185,13 +250,23 @@ fn churn<A: Asset>(mut assets: ResMut<Assets<A>>, mut leaker: ResMut<Leaker<A>>)
185
250
}
186
251
}
187
252
253
+ fn churn_using_insert < A : Asset > ( mut assets : ResMut < Assets < A > > , leaker : Res < Leaker < A > > ) {
254
+ for id in & leaker. 0 {
255
+ let asset = assets. remove ( id. id ( ) ) . unwrap ( ) ;
256
+ assets. insert ( id. id ( ) , asset) ;
257
+ }
258
+ }
259
+
188
260
fn crash_on_mesh_leak_detection ( diagnostic_store : Res < DiagnosticsStore > ) {
189
- if let ( Some ( render_meshes) , Some ( allocations) ) = (
261
+ if let ( Some ( render_meshes) , Some ( slab_size ) , Some ( allocations) ) = (
190
262
diagnostic_store
191
263
. get_measurement (
192
264
& RenderAssetDiagnosticPlugin :: < RenderMesh > :: render_asset_diagnostic_path ( ) ,
193
265
)
194
266
. filter ( |diag| diag. value > 0. ) ,
267
+ diagnostic_store
268
+ . get_measurement ( MeshAllocatorDiagnosticPlugin :: slabs_size_diagnostic_path ( ) )
269
+ . filter ( |diag| diag. value > 0. ) ,
195
270
diagnostic_store
196
271
. get_measurement ( MeshAllocatorDiagnosticPlugin :: allocations_diagnostic_path ( ) )
197
272
. filter ( |diag| diag. value > 0. ) ,
@@ -200,20 +275,31 @@ fn crash_on_mesh_leak_detection(diagnostic_store: Res<DiagnosticsStore>) {
200
275
allocations. value < render_meshes. value * 10. ,
201
276
"Detected leak"
202
277
) ;
278
+ assert ! (
279
+ slab_size. value < ( 1 << 30 ) as f64 ,
280
+ "Exceeded 1GB of allocations."
281
+ ) ;
203
282
}
204
283
}
205
284
206
285
fn crash_on_material_leak_detection < M : Material > ( diagnostic_store : Res < DiagnosticsStore > ) {
207
- if let ( Some ( materials) , Some ( allocations) ) = (
286
+ if let ( Some ( materials) , Some ( slab_size ) , Some ( allocations) ) = (
208
287
diagnostic_store
209
288
. get_measurement (
210
289
& RenderAssetDiagnosticPlugin :: < PreparedMaterial < M > > :: render_asset_diagnostic_path ( ) ,
211
290
)
212
291
. filter ( |diag| diag. value > 0. ) ,
292
+ diagnostic_store
293
+ . get_measurement ( & MaterialAllocatorDiagnosticPlugin :: < M > :: slabs_size_diagnostic_path ( ) )
294
+ . filter ( |diag| diag. value > 0. ) ,
213
295
diagnostic_store
214
296
. get_measurement ( & MaterialAllocatorDiagnosticPlugin :: < M > :: allocations_diagnostic_path ( ) )
215
297
. filter ( |diag| diag. value > 0. ) ,
216
298
) {
217
299
assert ! ( allocations. value < materials. value * 10. , "Detected leak" ) ;
300
+ assert ! (
301
+ slab_size. value < ( 1 << 30 ) as f64 ,
302
+ "Exceeded 1GB of allocations."
303
+ ) ;
218
304
}
219
305
}
0 commit comments