Add FastAPI interface between the game and map.

A possible explanation for the infrequent CTDs we've been seeing since
adding fast forward is that QWebChannel doesn't keep a reference to the
python objects that it passes to js, so if the object is GC'd before the
front end is done with it, it crashes.

We don't really like QWebChannel anyway, so this begins replacing that
with FastAPI.
This commit is contained in:
Dan Albert
2022-02-13 14:22:05 -08:00
parent 1df31b2496
commit 350f08be2f
33 changed files with 419 additions and 330 deletions

View File

@@ -10,6 +10,7 @@ from PySide2.QtCore import QUrl
from PySide2.QtWebChannel import QWebChannel
from PySide2.QtWebEngineWidgets import (
QWebEnginePage,
QWebEngineSettings,
QWebEngineView,
)
@@ -48,6 +49,11 @@ class QLiberationMap(QWebEngineView):
self.channel.registerObject("game", self.map_model)
self.page = LoggingWebPage(self)
# Required to allow "cross-origin" access from file:// scoped canvas.html to the
# localhost HTTP backend.
self.page.settings().setAttribute(
QWebEngineSettings.LocalContentCanAccessRemoteUrls, True
)
self.page.setWebChannel(self.channel)
self.page.load(
QUrl.fromLocalFile(str(Path("resources/ui/map/canvas.html").resolve()))