Skip to content
This repository was archived by the owner on Sep 7, 2023. It is now read-only.

Commit a8a81d9

Browse files
authored
Merge pull request #71 from THU-ASTA/develop
Fix bugs
2 parents bc3c5a4 + b9e2522 commit a8a81d9

File tree

5 files changed

+45
-25
lines changed

5 files changed

+45
-25
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,30 @@ assignees: ''
88
---
99

1010
**Describe the bug**
11+
1112
A clear and concise description of what the bug is.
1213

1314
**To Reproduce**
15+
1416
Steps to reproduce the behavior:
1517
1. Go to '...'
1618
2. Click on '....'
1719
3. Scroll down to '....'
1820
4. See error
1921

2022
**Expected behavior**
23+
2124
A clear and concise description of what you expected to happen.
2225

2326
**Screenshots**
27+
2428
If applicable, add screenshots to help explain your problem.
2529

2630
**Platform (please complete the following information):**
31+
2732
- OS: [e.g. Windows 10 21H2]
28-
- Version [e.g. v24.0.0]
33+
- Version: [e.g. v24.0.0]
2934

3035
**Additional context**
36+
3137
Add any other context about the problem here.

Source/Game.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,6 @@ public void Refresh()
445445
this.End();
446446
}
447447

448-
// Actually, whether the CarPosition is null or not, the game should generate orders anyway.
449-
// So, I take the function 'GenerateOrder' out of the function 'Refresh'
450-
// For more details, please check the reference of this function-- 'Refresh'
451-
452-
// this.GenerateOrder();
453-
454448
this.TakeAndDeliverOrder();
455449

456450
this.ScoreMoving();
@@ -901,7 +895,7 @@ void TakeAndDeliverOrder()
901895
if (order.Status == OrderStatusType.Pending)
902896
{
903897
// Check if the capacity is full.
904-
if (deliveringOrderNumber > Game.OrderDeliveryCapacity)
898+
if (deliveringOrderNumber >= Game.OrderDeliveryCapacity)
905899
{
906900
continue;
907901
}

Source/MainWindow.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ public MainWindow()
275275
/// </summary>
276276
private void RefreshAll()
277277
{
278+
// Do not refresh if the camera is changing.
279+
if (this._camera == null)
280+
{
281+
return;
282+
}
283+
278284
// Update the timer interval.
279285
if (this.timer.Interval != (int)(this._camera.Fps))
280286
{
@@ -479,7 +485,8 @@ private void Communicate()
479485
id: -1
480486
));
481487

482-
if (this._orderToTransmitList.Count > 1) {
488+
if (this._orderToTransmitList.Count > 1)
489+
{
483490
this._orderToTransmitList.RemoveAt(0);
484491
}
485492

@@ -507,9 +514,9 @@ private void Communicate()
507514
/// </summary>
508515
private void ProcessCameraFrame()
509516
{
510-
// Read the camera frame.
517+
// Read a frame from the camera.
511518
Mat frame = new Mat();
512-
if (!Camera.Read(frame))
519+
if (!this._camera.Read(frame))
513520
{
514521
return;
515522
}

Source/PacketGetStatusHost.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,10 @@ public PacketGetStatusHost(byte[] bytes)
129129

130130
public override byte[] GetBytes()
131131
{
132-
// Used to judge whether the lastest pending order is null, if not, the length of byte array will be added with 32;
133-
bool lastestPendingOrderIsNull = (this._latestPendingOrder == null);
134132

135133
var data = new byte[
136134
1 + 4 + 4 + 8 + 4 +
137-
(1 + 28 * this._orderInDeliveryList.Count) + 28 * Convert.ToInt32(!lastestPendingOrderIsNull)
135+
(1 + 28 * this._orderInDeliveryList.Count) + 28 * 1
138136
];
139137

140138
int index = 0;
@@ -222,7 +220,8 @@ public override byte[] GetBytes()
222220

223221

224222
#region The latest pending order.
225-
if (!lastestPendingOrderIsNull)
223+
// Used to judge whether the lastest pending order is null, if it is, then a null order with id -1 will be created;
224+
if (this._latestPendingOrder != null)
226225
{
227226
#region The departure position.
228227

@@ -255,6 +254,14 @@ public override byte[] GetBytes()
255254
BitConverter.GetBytes(this._latestPendingOrder.Id).CopyTo(data, index);
256255
index += 4;
257256
}
257+
else
258+
{
259+
// The bytes of a null order is 0, except for -1 id
260+
index += 4 * 6;
261+
// The order ID.
262+
BitConverter.GetBytes((int)-1).CopyTo(data, index);
263+
index += 4;
264+
}
258265
#endregion
259266

260267
// Generate the header.

Source/SettingsWindow.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@ private void ApplyConfig()
7070
this._mainWindow.Config = this._config;
7171

7272
// Apply the camera configurations
73-
this._mainWindow.Camera.Release();
74-
75-
var camera = new VideoCapture();
73+
var camera = this._mainWindow.Camera;
74+
this._mainWindow.Camera = null;
75+
camera.Release();
76+
camera = new VideoCapture();
7677

7778
camera.Open(this._mainWindow.Config.Camera);
78-
79+
7980
this._mainWindow.CameraFrameSize = new OpenCvSharp.Size(
8081
camera.FrameWidth,
8182
camera.FrameHeight
@@ -245,7 +246,7 @@ private void SyncFormToConfig()
245246
}
246247
}
247248
},
248-
Camera = Convert.ToInt32(this.comboBoxCamera.Text)
249+
Camera = this.comboBoxCamera.SelectedIndex
249250
};
250251
}
251252
catch (System.FormatException)
@@ -303,9 +304,6 @@ private void SyncConfigToForm()
303304
this.comboBoxBaudrateVehicleB.Text =
304305
this._config.Vehicles[CampType.B].Baudrate.ToString();
305306

306-
this.comboBoxCamera.Text =
307-
this._config.Camera.ToString();
308-
309307
this.Refresh();
310308
}
311309

@@ -329,7 +327,11 @@ private void UpdateAvailableCameras()
329327
Action safeWrite = delegate
330328
{
331329
this.comboBoxCamera.Items.Add(cameraPort);
332-
if (this.comboBoxCamera.Items.Count > 0)
330+
if (this.comboBoxCamera.Items.Count > this._config.Camera)
331+
{
332+
this.comboBoxCamera.SelectedIndex = this._config.Camera;
333+
}
334+
else
333335
{
334336
this.comboBoxCamera.SelectedIndex = 0;
335337
}
@@ -339,7 +341,11 @@ private void UpdateAvailableCameras()
339341
else
340342
{
341343
this.comboBoxCamera.Items.Add(cameraPort);
342-
if (this.comboBoxCamera.Items.Count > 0)
344+
if (this.comboBoxCamera.Items.Count > this._config.Camera)
345+
{
346+
this.comboBoxCamera.SelectedIndex = this._config.Camera;
347+
}
348+
else
343349
{
344350
this.comboBoxCamera.SelectedIndex = 0;
345351
}

0 commit comments

Comments
 (0)