Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

chore(native): the self-check waits for a foreground window before opening the overlay

esengine9534ecb382a2
diff --git a/native/host/platform/desktop.cpp b/native/host/platform/desktop.cpp
index 672e524db..c8ab90973 100644
--- a/native/host/platform/desktop.cpp
+++ b/native/host/platform/desktop.cpp
@@ -603,6 +603,10 @@ int main(int argc, char** argv) {
if (!shown) {
shown = true;
SDL_ShowWindow(window);
+ // And in front: a game that opens behind the window it was
+ // launched from is one the player has to go find, and a store
+ // draws its overlay only over the FOREGROUND window.
+ SDL_RaiseWindow(window);
}
}
if (eshost::quitRequested()) running = false;
diff --git a/native/host/steam/SteamApi.cpp b/native/host/steam/SteamApi.cpp
index 180a54861..ff7135e19 100644
--- a/native/host/steam/SteamApi.cpp
+++ b/native/host/steam/SteamApi.cpp
@@ -13,6 +13,7 @@
*/
#include "steam/SteamApi.hpp"
+#include <chrono>
#include <cstdio>
#include <cstring>
@@ -131,9 +132,12 @@ constexpr std::int32_t kGameOverlayActivated = 331;
/** Its first byte: non-zero while the overlay covers the game. */
constexpr int kOverlayActiveOffset = 0;
-/** Which frame the self-check opens the overlay on — late enough that there is a
- * window to draw over. */
-constexpr int kSelfCheckPump = 120;
+/** How long after Steam comes up the self-check opens the overlay.
+ *
+ * Seconds, not frames: an uncapped host runs a thousand frames in the first one,
+ * so a frame count fires before the window is on screen — and opening the overlay
+ * then is a refusal that looks exactly like a callback that never came. */
+constexpr std::chrono::seconds kSelfCheckDelay{6};
/** Steam's error buffer is a fixed 1024 bytes (SteamErrMsg). */
constexpr int kErrMsgSize = 1024;
@@ -334,8 +338,10 @@ void SteamApi::pump() {
// The self-check opens the overlay from the FRAME, not from boot: Steam
// refuses to draw over a window that does not exist yet, and a refusal looks
// exactly like a callback that never came.
- if (traceCallbacks_ && ++pumps_ == kSelfCheckPump) {
- ESHOST_LOGI("steam: self-check opening the overlay at pump %d", kSelfCheckPump);
+ if (traceCallbacks_ && !selfCheckDone_
+ && std::chrono::steady_clock::now() - traceStart_ >= kSelfCheckDelay) {
+ selfCheckDone_ = true;
+ ESHOST_LOGI("steam: self-check opening the overlay");
activateOverlay();
}
g_fns.dispatchRunFrame(pipe_);
diff --git a/native/host/steam/SteamApi.hpp b/native/host/steam/SteamApi.hpp
index 62071ddb0..a58c630c9 100644
--- a/native/host/steam/SteamApi.hpp
+++ b/native/host/steam/SteamApi.hpp
@@ -23,6 +23,7 @@
*/
#pragma once
+#include <chrono>
#include <cstdint>
#include <functional>
#include <string>
@@ -93,7 +94,10 @@ class SteamApi {
void activateOverlay();
/** Log every callback the dispatcher hands out — the self-check's eyes. */
- void traceCallbacks(bool on) { traceCallbacks_ = on; }
+ void traceCallbacks(bool on) {
+ traceCallbacks_ = on;
+ traceStart_ = std::chrono::steady_clock::now();
+ }
/** Why {@link init} answered false, for the boot record. Empty on success. */
const std::string& lastError() const { return error_; }
@@ -106,7 +110,8 @@ class SteamApi {
std::int32_t pipe_ = 0;
std::function<void(bool)> overlay_;
bool traceCallbacks_ = false;
- int pumps_ = 0;
+ bool selfCheckDone_ = false;
+ std::chrono::steady_clock::time_point traceStart_{};
void* friends_ = nullptr;
std::string error_;
};