From 5352d031debb32237e64065cafcc31d253dc83df Mon Sep 17 00:00:00 2001 From: Dominik Tugend Date: Sat, 30 Oct 2021 17:59:40 +0200 Subject: [PATCH] Probably still has a memory leak somewhere. --- .../assets/examples/default/drawing.html | 29 +++++++++++++------ .../assets/examples/default/index.html | 11 ------- afx-cefhud-interop/simple_handler.cc | 13 --------- 3 files changed, 20 insertions(+), 33 deletions(-) diff --git a/afx-cefhud-interop/assets/examples/default/drawing.html b/afx-cefhud-interop/assets/examples/default/drawing.html index b48795b..b15f0fe 100644 --- a/afx-cefhud-interop/assets/examples/default/drawing.html +++ b/afx-cefhud-interop/assets/examples/default/drawing.html @@ -101,8 +101,8 @@

Last game events:

o.pos = float4(i.pos, 1); o.pos = mul( o.pos, World ); o.pos = mul( o.pos, View ); - o.pos = mul( o.pos, Projection ); - o.pos /= o.pos.w; + o.pos = mul( o.pos, Projection ); + o.pos /= o.pos.w; o.c = float4(o.pos.x,0,o.pos.y,1); o.t0 = i.t0; @@ -238,11 +238,24 @@

Last game events:

this.vertexBuffers = { "rect": null }; + + async function waitForFirstSucessfulPaint() { + let painted = false; + while(!painted) { + Utils.toPromise(self.interop, "waitForCefFrame").then(()=>{ + painted = true; + }); + await Utils.sleepPromise(1000); + } + } - Utils.toPromise(self.interop, "sendMessage", self.args.indexInteropId, JSON.stringify({ - "id": "drawingCreated", - "args": [interop.id] - })); + + waitForFirstSucessfulPaint().then(()=>{ + Utils.toPromise(self.interop, "sendMessage", self.args.indexInteropId, JSON.stringify({ + "id": "drawingCreated", + "args": [interop.id] + })); + }); } AfxDrawingInterop.prototype.onDeviceReset = async function() { @@ -632,8 +645,7 @@

Last game events:

// paint last frame (if wanted): if(lastRender && lastRender.onPaint) { - if(lastRender.sync) - await Utils.toPromise(self.interop, "waitForCefFrame"); + await Utils.toPromise(self.interop, "waitForCefFrame"); if(self.lastShareHandle) { @@ -743,7 +755,6 @@

Last game events:

// Ensure resources: let renderSettings = { - "sync": this.indexSettings.sync, "x": x, "y": y, "width": width, diff --git a/afx-cefhud-interop/assets/examples/default/index.html b/afx-cefhud-interop/assets/examples/default/index.html index c72957e..6be1fa5 100644 --- a/afx-cefhud-interop/assets/examples/default/index.html +++ b/afx-cefhud-interop/assets/examples/default/index.html @@ -32,10 +32,6 @@

Default example

Drawing connected: n/a

Settings

-
- - -
@@ -66,16 +62,12 @@

Settings

this.elDrawingStatus = document.getElementById('drawingStatus'); function updateSettings(e) { - if(e.target == self.elSync && !e.target.checked) self.elBg.checked = false; - else if(e.target == self.elBg && e.target.checked) self.elSync.checked = true; - if(!self.engineConnected) return; let settings = {}; //settings[e.target.name.toString()] = e.target.checked; settings = { - "sync": self.elSync.checked, "bg": self.elBg.checked }; @@ -84,9 +76,7 @@

Settings

"args": [settings] })); } - this.elSync = document.getElementById('sync'); this.elBg = document.getElementById('bg'); - this.elSync.addEventListener("change", updateSettings); this.elBg.addEventListener("change", updateSettings); this.messageHandlers = { @@ -109,7 +99,6 @@

Settings

this.engineInteropId = engineInteropId; let settings = { - "sync": this.elSync.checked, "bg": this.elBg.checked }; diff --git a/afx-cefhud-interop/simple_handler.cc b/afx-cefhud-interop/simple_handler.cc index 700e30a..492bf92 100644 --- a/afx-cefhud-interop/simple_handler.cc +++ b/afx-cefhud-interop/simple_handler.cc @@ -277,19 +277,6 @@ bool SimpleHandler::OnProcessMessageReceived( browser->GetMainFrame()->SendProcessMessage(PID_RENDERER, response); return true; } else if (name == "afx-paint") { - - { - std::unique_lock lock(m_BrowserMutex); - auto it = m_Browsers.find(browser->GetIdentifier()); - if (it != m_Browsers.end()) { - if (it->second.FirstRender) { - it->second.FirstRender = false; - lock.unlock(); - browser->GetHost()->SendExternalBeginFrame(); - } - } - } - browser->GetHost()->SendExternalBeginFrame(); } else if (name == "afx-use-clear") {