Fix réseau : file d'instanciation sur le thread de jeu (crash GL du TCPReader)

- Le TCPReader 2017 instaniait les prefabs réseau depuis son thread (pas de
  contexte OpenGL -> crash natif glGenTextures dès le premier prefab
  texturé) — bug jamais rencontré car le multi n'a jamais été testé à 2
- Network : pendingInstantiations (file) consommée par update() sur le thread
  de jeu
- Test coop 2 clients desktop réels contre le matchmaker local : les 2
  clients dans la même partie (game id=0), l'hôte instancie et envoie 36
  objets réseau (lockers + player_other) ; handshake player_join du client
  restant partiel (protocole 2017 jamais testé à 2 — tracé TODO)
- TODO/CHANGELOG mis à jour
This commit is contained in:
Siphonight 2026-11-15 17:50:23 +01:00
parent 6a250c192f
commit 0b41b91247
2 changed files with 52 additions and 17 deletions

18
TODO.md
View File

@ -182,6 +182,18 @@ reste du portage Android.
(repo Matchmaking-Server, Node/UDP) fonctionne tel quel ; client
configurable (env LS_MP_HOST/LS_MP_PORT desktop, PlayerPrefs
mp_host/mp_port Android, défaut = serveur d'origine mort) ; test
desktop local E2E réussi (join → game_create → niveau multi chargé).
Restant : test coop à 2 clients réels (émulateur zombie au moment du
test) + déploiement serveur au choix de l'utilisateur
desktop local E2E réussi (join → game_create → niveau multi chargé)
- [x] Multi 2 clients réels — FAIT (v0.7.0, desktop×2 contre le matchmaker
local) : les 2 clients dans la MÊME partie (serveur : game id=0 avec 2
joueurs) ; fix majeur au passage : le TCPReader 2017 instaniait les
prefabs réseau depuis le thread réseau SANS contexte OpenGL (crash
natif glGenTextures) → file d'instanciation traitée sur le thread de
jeu (Network.handlePendingInstantiations) ; l'hôte instancie et envoie
36 objets réseau (lockers + player_other) au client
- [ ] Multi : handshake P2P restant — le client B ne reçoit pas le
player_join de l'hôte (direction des connexions TCP 2017 : l'hôte se
connecte à 2829/2830 au lieu du port TCP de B) — protocole jamais
testé à 2 chez les équipes d'origine ; à debugger avec les logs
(serveur + client)
- [ ] Test coop sur émulateur (client Android via 10.0.2.2) — BLOQUÉ : AVD
zombie (processus 91234 état UE, impossible à tuer sans redémarrage)

View File

@ -131,6 +131,9 @@ public class Network {
}
private static void update() {
// Instanciations réseau reçues du TCPReader : à traiter SUR LE THREAD
// DE JEU (le thread réseau n'a pas de contexte OpenGL).
handlePendingInstantiations();
if (System.currentTimeMillis() >= lastUpdate + 1000 / UPDATES_PER_SECOND) {
lastUpdate = System.currentTimeMillis();
ByteBuffer data = ByteBuffer.allocate(
@ -434,23 +437,43 @@ public class Network {
return message;
}
/*
* File des instanciations reçues par le TCPReader : ce thread n'a PAS de
* contexte OpenGL (GLFW/GL 3.2 = un seul thread propriétaire) et crashait
* nativement (glGenTextures) dès qu'il instaniait un prefab avec textures
* — bug 2017 jamais vu car le multi n'a jamais été testé avec des prefabs
* texturés. La file est consommée par update() sur le thread de jeu.
*/
private static final java.util.ArrayList<String> pendingInstantiations = new java.util.ArrayList<>();
private static void processInstantiation(String message) throws IOException {
String[] split = message.split(SPLIT_DIVIDER);
GameObject gameObject = PrefabManager.loadPrefab(split[0]);
gameObject.networkId = Integer.parseInt(split[1]);
Vector2 position = new Vector2(Float.parseFloat(split[2]), Float.parseFloat(split[3]));
int playerId = Integer.parseInt(split[4]);
List<NetworkBehaviour> networkBehaviours = gameObject.getComponentsOfType(NetworkBehaviour.class);
HashMap<String, Integer> networkIds = new HashMap<>();
for (int i = 0; i < networkBehaviours.size(); i++) {
networkIds.put(split[5 + (i * 2)], Integer.parseInt(split[6 + (i * 2)]));
synchronized (pendingInstantiations) {
pendingInstantiations.add(message);
}
for (NetworkBehaviour nb : networkBehaviours) {
nb.setPlayerId(playerId);
nb.setNetworkId(networkIds.get(nb.getClass().getCanonicalName()));
}
private static void handlePendingInstantiations() {
synchronized (pendingInstantiations) {
while (!pendingInstantiations.isEmpty()) {
String message = pendingInstantiations.remove(0);
String[] split = message.split(SPLIT_DIVIDER);
GameObject gameObject = PrefabManager.loadPrefab(split[0]);
gameObject.networkId = Integer.parseInt(split[1]);
Vector2 position = new Vector2(Float.parseFloat(split[2]), Float.parseFloat(split[3]));
int playerId = Integer.parseInt(split[4]);
List<NetworkBehaviour> networkBehaviours = gameObject.getComponentsOfType(NetworkBehaviour.class);
HashMap<String, Integer> networkIds = new HashMap<>();
for (int i = 0; i < networkBehaviours.size(); i++) {
networkIds.put(split[5 + (i * 2)], Integer.parseInt(split[6 + (i * 2)]));
}
for (NetworkBehaviour nb : networkBehaviours) {
nb.setPlayerId(playerId);
nb.setNetworkId(networkIds.get(nb.getClass().getCanonicalName()));
}
GameObject go = GameObject.instantiate(gameObject, position);
networkObjects.put(go.networkId, new InstantiationData(split[0], position, playerId, gameObject));
}
}
GameObject go = GameObject.instantiate(gameObject, position);
networkObjects.put(go.networkId, new InstantiationData(split[0], position, playerId, gameObject));
}
public static void destroy(GameObject gameObject) {