Periodically free memory in the middle of screenshot test, to avoid

running out on my current machine. Fixes #671.

Finally regenerate screenshots for the first time in ages... just
blindly accepting everything, because the slightly different screen size
means everything was slightly shifted down.
This commit is contained in:
Dustin Carlino 2021-06-09 14:31:40 -07:00
parent 60352747bf
commit d827673ace
10 changed files with 79 additions and 21 deletions

View File

@ -641,9 +641,9 @@
"compressed_size_bytes": 3360875 "compressed_size_bytes": 3360875
}, },
"data/input/gb/great_kneighton/screenshots/center.zip": { "data/input/gb/great_kneighton/screenshots/center.zip": {
"checksum": "691b1100a3024d75e40fa5421804816b", "checksum": "d63d28848433aee9583f9cda45055cb6",
"uncompressed_size_bytes": 40408055, "uncompressed_size_bytes": 40511903,
"compressed_size_bytes": 40392956 "compressed_size_bytes": 40497136
}, },
"data/input/gb/halsnead/osm/center.osm": { "data/input/gb/halsnead/osm/center.osm": {
"checksum": "9b4aedf25220e29e11d0970cf7c70a26", "checksum": "9b4aedf25220e29e11d0970cf7c70a26",
@ -1381,9 +1381,9 @@
"compressed_size_bytes": 4109889 "compressed_size_bytes": 4109889
}, },
"data/input/pl/krakow/screenshots/center.zip": { "data/input/pl/krakow/screenshots/center.zip": {
"checksum": "29a86e25c6eccfb37af0b59e202b0e14", "checksum": "166d773faf1b288a220fc0b695d014cb",
"uncompressed_size_bytes": 29802245, "uncompressed_size_bytes": 29954067,
"compressed_size_bytes": 29797624 "compressed_size_bytes": 29949440
}, },
"data/input/pl/warsaw/osm/center.osm": { "data/input/pl/warsaw/osm/center.osm": {
"checksum": "b41830dd375674ffc9f7ec15d6cf9c0c", "checksum": "b41830dd375674ffc9f7ec15d6cf9c0c",
@ -1861,9 +1861,9 @@
"compressed_size_bytes": 439447 "compressed_size_bytes": 439447
}, },
"data/input/us/phoenix/screenshots/tempe.zip": { "data/input/us/phoenix/screenshots/tempe.zip": {
"checksum": "f4f15a4f48ef39cb9b7266cb40d2be9a", "checksum": "45a9cfd163b3841fe31ef0c562492c33",
"uncompressed_size_bytes": 7339279, "uncompressed_size_bytes": 7522637,
"compressed_size_bytes": 7336881 "compressed_size_bytes": 7520470
}, },
"data/input/us/providence/osm/downtown.osm": { "data/input/us/providence/osm/downtown.osm": {
"checksum": "463b986adc83ae4d1174496a4ce744d1", "checksum": "463b986adc83ae4d1174496a4ce744d1",
@ -2166,24 +2166,24 @@
"compressed_size_bytes": 6482033 "compressed_size_bytes": 6482033
}, },
"data/input/us/seattle/screenshots/downtown.zip": { "data/input/us/seattle/screenshots/downtown.zip": {
"checksum": "541b6e45836d37d797bed7531a03e421", "checksum": "dafeea78cd662199cc321aef8494295f",
"uncompressed_size_bytes": 22965800, "uncompressed_size_bytes": 22998289,
"compressed_size_bytes": 22957392 "compressed_size_bytes": 22990295
}, },
"data/input/us/seattle/screenshots/lakeslice.zip": { "data/input/us/seattle/screenshots/lakeslice.zip": {
"checksum": "ac9a50dd97577178494561ea1fd7951f", "checksum": "1a8bd605773e4a8e36a66a9292dee20c",
"uncompressed_size_bytes": 22290371, "uncompressed_size_bytes": 22427709,
"compressed_size_bytes": 22283926 "compressed_size_bytes": 22421438
}, },
"data/input/us/seattle/screenshots/montlake.zip": { "data/input/us/seattle/screenshots/montlake.zip": {
"checksum": "fd66ccdc843e1c085d5e6c33f239f8d3", "checksum": "0a750cdfe36c6250fe793c98e05ee1d7",
"uncompressed_size_bytes": 4363199, "uncompressed_size_bytes": 4381887,
"compressed_size_bytes": 4362963 "compressed_size_bytes": 4381657
}, },
"data/input/us/seattle/screenshots/udistrict.zip": { "data/input/us/seattle/screenshots/udistrict.zip": {
"checksum": "9d0723df3ae3a9f19d67d3c0bff819bb", "checksum": "c9903c981ab1cccd9d3bd6cda788bfcc",
"uncompressed_size_bytes": 11021512, "uncompressed_size_bytes": 11086681,
"compressed_size_bytes": 11018263 "compressed_size_bytes": 11083687
}, },
"data/input/us/seattle/trips_2014.csv": { "data/input/us/seattle/trips_2014.csv": {
"checksum": "d4a8e733045b28c0385fb81359d6df03", "checksum": "d4a8e733045b28c0385fb81359d6df03",

View File

@ -864,6 +864,10 @@ impl SharedAppState for App {
fn before_quit(&self, canvas: &Canvas) { fn before_quit(&self, canvas: &Canvas) {
CameraState::save(canvas, self.primary.map.get_name()); CameraState::save(canvas, self.primary.map.get_name());
} }
fn free_memory(&mut self) {
self.primary.draw_map.free_memory();
}
} }
/// Load an extra GeoJSON file, and add the area to the map dynamically. /// Load an extra GeoJSON file, and add the area to the map dynamically.

View File

@ -228,6 +228,10 @@ impl DrawBuilding {
); );
} }
} }
pub fn clear_rendering(&mut self) {
*self.label.borrow_mut() = None;
}
} }
impl Renderable for DrawBuilding { impl Renderable for DrawBuilding {

View File

@ -151,6 +151,10 @@ impl DrawIntersection {
.make_polygons(Distance::meters(0.3)); .make_polygons(Distance::meters(0.3));
Some((octagon, pole, last_line.angle())) Some((octagon, pole, last_line.angle()))
} }
pub fn clear_rendering(&mut self) {
*self.draw_default.borrow_mut() = None;
}
} }
impl Renderable for DrawIntersection { impl Renderable for DrawIntersection {

View File

@ -179,6 +179,10 @@ impl DrawLane {
batch batch
} }
pub fn clear_rendering(&mut self) {
*self.draw_default.borrow_mut() = None;
}
} }
impl Renderable for DrawLane { impl Renderable for DrawLane {

View File

@ -514,4 +514,23 @@ impl DrawMap {
} }
self.draw_all_building_driveways = ctx.upload(batch); self.draw_all_building_driveways = ctx.upload(batch);
} }
pub fn free_memory(&mut self) {
// Clear the lazily evaluated zoomed-in details
for r in &mut self.roads {
r.clear_rendering();
}
for l in self.lanes.values_mut() {
l.clear_rendering();
}
for i in &mut self.intersections {
i.clear_rendering();
}
for b in &mut self.buildings {
b.clear_rendering();
}
for pl in &mut self.parking_lots {
pl.clear_rendering();
}
}
} }

View File

@ -315,6 +315,10 @@ impl<T: 'static> SharedAppState for SimpleApp<T> {
fn before_quit(&self, canvas: &Canvas) { fn before_quit(&self, canvas: &Canvas) {
CameraState::save(canvas, self.map.get_name()); CameraState::save(canvas, self.map.get_name());
} }
fn free_memory(&mut self) {
self.draw_map.free_memory();
}
} }
struct SimpleWarper { struct SimpleWarper {

View File

@ -19,6 +19,10 @@ pub trait SharedAppState {
fn dump_before_abort(&self, _: &Canvas) {} fn dump_before_abort(&self, _: &Canvas) {}
/// Called before a normal exit, like window close /// Called before a normal exit, like window close
fn before_quit(&self, _: &Canvas) {} fn before_quit(&self, _: &Canvas) {}
/// If widgetry determines the video card is low on memory, this may be called. The application
/// should make its best effort to delete any unused Drawables.
fn free_memory(&mut self) {}
} }
pub(crate) struct App<A: SharedAppState> { pub(crate) struct App<A: SharedAppState> {

View File

@ -158,6 +158,10 @@ impl<A: SharedAppState> State<A> {
prerender.inner.draw_finished(g.inner); prerender.inner.draw_finished(g.inner);
naming_hint naming_hint
} }
pub(crate) fn free_memory(&mut self) {
self.app.shared_app_state.free_memory();
}
} }
/// Customize how widgetry works. Most of these settings can't be changed after starting. /// Customize how widgetry works. Most of these settings can't be changed after starting.

View File

@ -31,12 +31,23 @@ pub(crate) fn screenshot_everything<A: SharedAppState>(
state.canvas.cam_zoom = zoom; state.canvas.cam_zoom = zoom;
std::fs::create_dir_all(dir_path)?; std::fs::create_dir_all(dir_path)?;
// See https://github.com/a-b-street/abstreet/issues/671 for context. Some maps are so large
// and detailed that they drain all memory on some video cards. As a workaround, just free up
// some of the objects in the middle of this test.
let free_memory_frequency = 10;
let mut cnt = 0;
for tile_y in 0..num_tiles_y { for tile_y in 0..num_tiles_y {
for tile_x in 0..num_tiles_x { for tile_x in 0..num_tiles_x {
timer.next(); timer.next();
state.canvas.cam_x = (tile_x as f64) * dims.width; state.canvas.cam_x = (tile_x as f64) * dims.width;
state.canvas.cam_y = (tile_y as f64) * dims.height; state.canvas.cam_y = (tile_y as f64) * dims.height;
cnt += 1;
if cnt % free_memory_frequency == 0 {
state.free_memory();
}
let suffix = state.draw(prerender, true).unwrap_or_else(String::new); let suffix = state.draw(prerender, true).unwrap_or_else(String::new);
// Sometimes the very first image captured is of the debug mode used to launch this. Not // Sometimes the very first image captured is of the debug mode used to launch this. Not