Skip to content

Commit

Permalink
Probably still has a memory leak somewhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtugend committed Oct 30, 2021
1 parent 0d59b3d commit 5352d03
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 33 deletions.
29 changes: 20 additions & 9 deletions afx-cefhud-interop/assets/examples/default/drawing.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ <h2>Last game events:</h2>
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;
Expand Down Expand Up @@ -238,11 +238,24 @@ <h2>Last game events:</h2>
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() {
Expand Down Expand Up @@ -632,8 +645,7 @@ <h2>Last game events:</h2>
// 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)
{
Expand Down Expand Up @@ -743,7 +755,6 @@ <h2>Last game events:</h2>
// Ensure resources:

let renderSettings = {
"sync": this.indexSettings.sync,
"x": x,
"y": y,
"width": width,
Expand Down
11 changes: 0 additions & 11 deletions afx-cefhud-interop/assets/examples/default/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ <h1>Default example</h1>
<p>Drawing connected: <span id="drawingStatus">n/a</span></p>
<h2>Settings</h2>
<form>
<div>
<input type="checkbox" id="sync" name="sync" value="1" checked="checked">
<label for="sync"> <b>Enable perfect sync</b> (lower FPS).</label>
</div>
<div>
<input type="checkbox" id="bg" name="bg" value="1" checked="checked">
<label for="bg"> <b>Draw game background</b> (for background effects, lower FPS).</label>
Expand Down Expand Up @@ -66,16 +62,12 @@ <h2>Settings</h2>
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
};

Expand All @@ -84,9 +76,7 @@ <h2>Settings</h2>
"args": [settings]
}));
}
this.elSync = document.getElementById('sync');
this.elBg = document.getElementById('bg');
this.elSync.addEventListener("change", updateSettings);
this.elBg.addEventListener("change", updateSettings);

this.messageHandlers = {
Expand All @@ -109,7 +99,6 @@ <h2>Settings</h2>
this.engineInteropId = engineInteropId;

let settings = {
"sync": this.elSync.checked,
"bg": this.elBg.checked
};

Expand Down
13 changes: 0 additions & 13 deletions afx-cefhud-interop/simple_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,6 @@ bool SimpleHandler::OnProcessMessageReceived(
browser->GetMainFrame()->SendProcessMessage(PID_RENDERER, response);
return true;
} else if (name == "afx-paint") {

{
std::unique_lock<std::mutex> 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") {
Expand Down

0 comments on commit 5352d03

Please sign in to comment.