From 0b41b912470d01cab803effb4833244ca8c324bf Mon Sep 17 00:00:00 2001 From: Siphonight Date: Sun, 15 Nov 2026 17:50:23 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20r=C3=A9seau=20:=20file=20d'instanciation?= =?UTF-8?q?=20sur=20le=20thread=20de=20jeu=20(crash=20GL=20du=20TCPReader)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- TODO.md | 18 +++++-- .../dethsquare/multiplayer/Network.java | 51 ++++++++++++++----- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/TODO.md b/TODO.md index badbaba..2654584 100644 --- a/TODO.md +++ b/TODO.md @@ -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) diff --git a/dethsquare/core/src/main/java/com/ezardlabs/dethsquare/multiplayer/Network.java b/dethsquare/core/src/main/java/com/ezardlabs/dethsquare/multiplayer/Network.java index 14b98cd..a9927c1 100644 --- a/dethsquare/core/src/main/java/com/ezardlabs/dethsquare/multiplayer/Network.java +++ b/dethsquare/core/src/main/java/com/ezardlabs/dethsquare/multiplayer/Network.java @@ -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 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 networkBehaviours = gameObject.getComponentsOfType(NetworkBehaviour.class); - HashMap 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 networkBehaviours = gameObject.getComponentsOfType(NetworkBehaviour.class); + HashMap 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) {