Skip to content

Commit 18920c6

Browse files
SkySailspepperoni505ZigTag
authored
fix: patch module based on reports from iniBuilds A350 launch (#15)
* fix: delta_time overflow * fix: wasm no longer panics on invalid data (2502 broken data now just looks silly rather than crashing) * fix: added PAVD to surface code enum * fix: add missing turn_direction enum --------- Co-authored-by: Jack Lavigne <[email protected]> Co-authored-by: Falcon <[email protected]>
1 parent a323df0 commit 18920c6

File tree

7 files changed

+53
-33
lines changed

7 files changed

+53
-33
lines changed

src/database/src/database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Database {
112112
ValueRef::Integer(int) => Some(Value::Number(Number::from(int))),
113113
ValueRef::Real(real) => Some(Value::Number(Number::from_f64(real).unwrap())),
114114
ValueRef::Null => None,
115-
ValueRef::Blob(_) => panic!("Unexpected value type Blob"),
115+
ValueRef::Blob(_) => None,
116116
};
117117

118118
if let Some(value) = value {

src/database/src/enums.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ pub enum TurnDirection {
6262
Left,
6363
#[serde(rename = "R")]
6464
Right,
65+
#[serde(rename = "E")]
66+
Either,
6567
}
6668

6769
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
@@ -366,6 +368,8 @@ pub enum RunwaySurface {
366368
Water,
367369
#[serde(rename = "BITU")]
368370
Bitumen,
371+
#[serde(rename = "PAVD")]
372+
Paved,
369373
#[serde(rename = "UNPV")]
370374
Unpaved,
371375
}

src/database/src/output/airspace.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub enum PathType {
2424
RhumbLine,
2525
#[serde(rename = "A")]
2626
Arc,
27+
#[serde(rename = "U")]
28+
Unknown,
2729
}
2830

2931
#[serde_with::skip_serializing_none]
@@ -48,16 +50,16 @@ impl Path {
4850
match boundary_char {
4951
'C' => Self {
5052
location: Coordinates {
51-
lat: arc_latitude.unwrap(),
52-
long: arc_longitude.unwrap(),
53+
lat: arc_latitude.unwrap_or_default(),
54+
long: arc_longitude.unwrap_or_default(),
5355
},
5456
arc: None,
5557
path_type: PathType::Circle,
5658
},
5759
'G' | 'H' => Self {
5860
location: Coordinates {
59-
lat: latitude.unwrap(),
60-
long: longitude.unwrap(),
61+
lat: latitude.unwrap_or_default(),
62+
long: longitude.unwrap_or_default(),
6163
},
6264
arc: None,
6365
path_type: match boundary_char {
@@ -67,24 +69,31 @@ impl Path {
6769
},
6870
'L' | 'R' => Self {
6971
location: Coordinates {
70-
lat: latitude.unwrap(),
71-
long: longitude.unwrap(),
72+
lat: latitude.unwrap_or_default(),
73+
long: longitude.unwrap_or_default(),
7274
},
7375
arc: Some(Arc {
7476
origin: Coordinates {
75-
lat: arc_latitude.unwrap(),
76-
long: arc_longitude.unwrap(),
77+
lat: arc_latitude.unwrap_or_default(),
78+
long: arc_longitude.unwrap_or_default(),
7779
},
78-
distance: arc_distance.unwrap(),
79-
bearing: arc_bearing.unwrap(),
80+
distance: arc_distance.unwrap_or_default(),
81+
bearing: arc_bearing.unwrap_or_default(),
8082
direction: match boundary_char {
8183
'R' => TurnDirection::Right,
8284
_ => TurnDirection::Left,
8385
},
8486
}),
8587
path_type: PathType::Arc,
8688
},
87-
_ => panic!("Invalid path type"),
89+
_ => Self {
90+
location: Coordinates {
91+
lat: 0.0,
92+
long: 0.0,
93+
},
94+
arc: None,
95+
path_type: PathType::Unknown,
96+
},
8897
}
8998
}
9099
}

src/database/src/output/fix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl Fix {
7070
"PI" => FixType::IlsNavaid,
7171
"D " => FixType::VhfNavaid,
7272
"EA" | "PC" => FixType::Waypoint,
73-
x => panic!("Unexpected table: '{x}'"),
73+
_ => FixType::None,
7474
});
7575

7676
Self {

src/database/src/output/procedure_leg.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ impl From<sql_structs::Procedures> for ProcedureLeg {
126126
ar: leg.authorization_required,
127127
fix: if leg.waypoint_identifier.is_some() {
128128
Some(Fix::from_row_data(
129-
leg.waypoint_latitude.unwrap(),
130-
leg.waypoint_longitude.unwrap(),
131-
leg.waypoint_identifier.unwrap(),
132-
leg.waypoint_icao_code.unwrap(),
129+
leg.waypoint_latitude.unwrap_or_default(),
130+
leg.waypoint_longitude.unwrap_or_default(),
131+
leg.waypoint_identifier.unwrap_or("ERROR".to_string()),
132+
leg.waypoint_icao_code.unwrap_or("UNKN".to_string()),
133133
Some(leg.airport_identifier.clone()),
134134
leg.waypoint_ref_table,
135135
leg.waypoint_description_code.clone(),
@@ -139,10 +139,11 @@ impl From<sql_structs::Procedures> for ProcedureLeg {
139139
},
140140
recommended_navaid: if leg.recommended_navaid.is_some() {
141141
Some(Fix::from_row_data(
142-
leg.recommended_navaid_latitude.unwrap(),
143-
leg.recommended_navaid_longitude.unwrap(),
144-
leg.recommended_navaid.unwrap(),
145-
leg.recommended_navaid_icao_code.unwrap(),
142+
leg.recommended_navaid_latitude.unwrap_or_default(),
143+
leg.recommended_navaid_longitude.unwrap_or_default(),
144+
leg.recommended_navaid.unwrap_or("ERROR".to_string()),
145+
leg.recommended_navaid_icao_code
146+
.unwrap_or("UNKN".to_string()),
146147
Some(leg.airport_identifier.clone()),
147148
leg.recommended_navaid_ref_table,
148149
leg.waypoint_description_code.clone(),
@@ -166,10 +167,10 @@ impl From<sql_structs::Procedures> for ProcedureLeg {
166167
turn_direction: leg.turn_direction,
167168
arc_center_fix: if leg.center_waypoint.is_some() {
168169
Some(Fix::from_row_data(
169-
leg.center_waypoint_latitude.unwrap(),
170-
leg.center_waypoint_longitude.unwrap(),
171-
leg.center_waypoint.unwrap(),
172-
leg.center_waypoint_icao_code.unwrap(),
170+
leg.center_waypoint_latitude.unwrap_or_default(),
171+
leg.center_waypoint_longitude.unwrap_or_default(),
172+
leg.center_waypoint.unwrap_or("ERROR".to_string()),
173+
leg.center_waypoint_icao_code.unwrap_or("UNKN".to_string()),
173174
Some(leg.airport_identifier),
174175
leg.center_waypoint_ref_table,
175176
leg.waypoint_description_code,

src/wasm/src/dispatcher.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub struct Dispatcher<'a> {
4949
database: Database,
5050
delta_time: std::time::Duration,
5151
queue: Rc<RefCell<Vec<Rc<RefCell<Task>>>>>,
52+
first_update: bool,
5253
}
5354

5455
impl Dispatcher<'_> {
@@ -57,17 +58,15 @@ impl Dispatcher<'_> {
5758
commbus: CommBus::default(),
5859
downloader: Rc::new(NavigationDataDownloader::new()),
5960
database: Database::new(),
60-
delta_time: std::time::Duration::from_secs(u64::MAX), /* Initialize to max so that we send a heartbeat on
61-
* the first update */
61+
delta_time: std::time::Duration::from_secs(0), /* Initialize to max so that we send a heartbeat on
62+
* the first update */
6263
queue: Rc::new(RefCell::new(Vec::new())),
64+
first_update: true,
6365
}
6466
}
6567

6668
pub fn on_msfs_event(&mut self, event: MSFSEvent) {
6769
match event {
68-
MSFSEvent::PostInitialize => {
69-
self.handle_initialized();
70-
}
7170
MSFSEvent::PreDraw(data) => {
7271
self.handle_update(data);
7372
}
@@ -96,11 +95,18 @@ impl Dispatcher<'_> {
9695
}
9796

9897
fn handle_update(&mut self, data: &sGaugeDrawData) {
98+
// On the first update, handle initialization code. Additionally, there are edge cases
99+
// where the delta time causes a panic so we need to skip the first update after that.
100+
if self.first_update {
101+
self.handle_initialized();
102+
self.first_update = false;
103+
return;
104+
}
99105
// Accumulate delta time for heartbeat
100106
self.delta_time += data.delta_time();
101107

102108
// Send heartbeat every 5 seconds
103-
if self.delta_time >= std::time::Duration::from_secs(5) {
109+
if self.delta_time >= std::time::Duration::from_secs(1) {
104110
Dispatcher::send_event(events::EventType::Heartbeat, None);
105111
self.delta_time = std::time::Duration::from_secs(0);
106112
}

src/wasm/src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn delete_folder_recursively(path: &Path, batch_size: Option<usize>) -> io::
2626
let path = entry.path();
2727
let path_type = get_path_type(&path);
2828

29-
if path.file_name().unwrap() == "" {
29+
if path.file_name().is_none_or(|val| val.is_empty()) {
3030
eprintln!("[NAVIGRAPH]: Bugged entry");
3131
continue;
3232
}
@@ -79,7 +79,7 @@ pub fn copy_files_to_folder(from: &Path, to: &Path) -> io::Result<()> {
7979
let path = entry.path();
8080
let path_type = get_path_type(&path);
8181

82-
if path.file_name().unwrap() == "" {
82+
if path.file_name().is_none_or(|val| val.is_empty()) {
8383
eprintln!("[NAVIGRAPH]: Bugged entry");
8484
continue;
8585
}

0 commit comments

Comments
 (0)