Skip to content

Commit b541d39

Browse files
committed
Fix update check failing at random
Although this code contains many optimizations, the "actual" fix is on line 26 of `check_updates.gml`: upon doing an HTTP request, GameMaker sends multiple callbacks to inform async events about the "progress" of the request, during which the `status` field on `async_load` will be 1. The `result` will only be available when `status == 0` (success), so we must ONLY stop processing the callbacks (setting `update_http` to -1) when this occurs. Previously, the script was setting `update_http` to -1 as soon as the first callback was received, which means `result` might not have been available yet. The `http_status` would also be `undefined` when this occurred, which meant that checking for the update would randomly fail. Read more about it here: https://manual.yoyogames.com/GameMaker_Language/GML_Reference/Asynchronous_Functions/HTTP/http_get.htm https://docs2.yoyogames.com/source/_build/2_interface/1_editors/events/async_events.html
1 parent c8e9117 commit b541d39

File tree

1 file changed

+45
-26
lines changed

1 file changed

+45
-26
lines changed

scripts/check_updates/check_updates.gml

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,58 @@ function check_updates() {
88
// 2: up to date
99
// 4: downloading update
1010

11-
12-
var release = -1
13-
try {
14-
if (async_load[? "id"] = update_http) {
15-
update_http = -1
16-
if (async_load[? "http_status"] = 200) {
17-
var res = async_load[? "result"];
18-
res = json_parse(res)
11+
if (async_load[? "id"] = update_http) {
12+
13+
// CHECK RECEIVED DATA:
14+
// show_debug_message(async_load[? "result"])
15+
// show_debug_message(async_load[? "status"])
16+
// show_debug_message(async_load[? "http_status"])
17+
18+
var status = async_load[? "status"];
19+
20+
if (status == -1) { // error
21+
update = -1
22+
return;
23+
}
24+
25+
else if (status == 0) { // success
26+
27+
if (async_load[? "http_status"] != 200) { // other status codes (403 - rate limit, etc.)
28+
update = -1;
29+
return;
30+
}
31+
32+
else {
33+
update_http = -1;
34+
35+
var res = async_load[? "result"];
36+
res = json_parse(res);
37+
1938
// Iterate array of releases and get the first (latest) release OR pre-release
39+
var release = -1;
2040
for (var i = 0; i < array_length(res); i++) {
2141
if (check_prerelease || !res[i].prerelease) {
2242
release = res[i];
23-
break
43+
break;
2444
}
2545
}
46+
47+
if (release != -1) {
48+
var new_version = string_replace(release.tag_name, "v", "");
49+
if (new_version == version) {
50+
update = 2;
51+
} else {
52+
if (question("Version " + new_version + " is available! Do you want to download it?", "Update available!")) {
53+
var download_url = release.assets[0].browser_download_url;
54+
update_download = http_get_file(download_url, update_file);
55+
update = 4;
56+
} else {
57+
update = 1;
58+
}
59+
}
60+
} else update = -1;
61+
2662
}
2763
}
28-
if (release != -1) {
29-
var new_version = string_replace(release.tag_name, "v", "")
30-
if (new_version == version) {
31-
update = 2
32-
} else {
33-
if (question("Version " + new_version + " is available! Do you want to download it?", "Update available!")) {
34-
var download_url = release.assets[0].browser_download_url
35-
update_download = http_get_file(download_url, update_file)
36-
update = 4
37-
} else {
38-
update = 1
39-
}
40-
}
41-
}
42-
} catch (e) {
43-
log("Update check failed: " + e.message + e.longMessage)
44-
update = -1
4564
}
4665
}

0 commit comments

Comments
 (0)