From 124e156cf12293926fc1615bc2e1f88fcb44e03e Mon Sep 17 00:00:00 2001 From: Siphonight Date: Mon, 16 Nov 2026 00:40:17 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20gel=20du=20MacBook=20au=20ballon=20:=20sp?= =?UTF-8?q?in=20TCPReader=20=C3=A0=20100%=20CPU=20par=20connexion=20morte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Le retour utilisateur 'la version desktop fait planter le macbook en softlock (ballon)' vient d'un spin infini : quand le pair ferme la connexion TCP, readLine() rend null instantanément et socket.isConnected() ne passe JAMAIS false (état local) -> la boucle tournait à 100% CPU PAR connexion morte, pour toujours. Chaque déconnexion du client multi (crash émulateur, force-stop) laissait un coeur à fond ; cumulé au jeu GL et à l'émulateur, le Mac gelait entièrement. Fix : null -> log + break, plus des gardes sur les readLine imbriqués (INSTANTIATE/DESTROY/REQUEST_STATE). Desktop traqué : Defend chargé + rendu confirmé visuellement. --- .../dethsquare/multiplayer/Network.java | 50 +++++++++++++------ 1 file changed, 34 insertions(+), 16 deletions(-) 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 3c730e7..2e49482 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 @@ -350,26 +350,44 @@ public class Network { socket.setKeepAlive(true); while (socket.isConnected()) { String command = in.readLine(); - if (command != null) { - switch (command) { - case INSTANTIATE: - processInstantiation(in.readLine()); - break; - case DESTROY: - processDestruction(in.readLine()); - break; - case REQUEST_STATE: - sendState(in.readLine()); - break; - default: - System.out.println("Unknown command:" + command); - break; - } + if (command == null) { + /* + * EOF = le pair a fermé la connexion. SANS ce garde, la + * boucle spinait à 100% CPU PAR CONNEXION MORTE pour + * toujours : readLine() rend null instantanément et + * isConnected() ne passe JAMAIS false sur une fermeture + * distante (état local seulement). C'était le gel du + * MacBook complet au ballon (retour v0.12.0 : chaque + * déconnexion du client multi laissait un cœur à + * fond, cumulé au jeu GL et à l'émulateur). + */ + GameLog.i("LS-NET", "Multiplayer : connexion TCP fermée par le pair"); + break; + } + switch (command) { + case INSTANTIATE: + String instantiateMsg = in.readLine(); + if (instantiateMsg == null) break; + processInstantiation(instantiateMsg); + break; + case DESTROY: + String destroyMsg = in.readLine(); + if (destroyMsg == null) break; + processDestruction(destroyMsg); + break; + case REQUEST_STATE: + String requestMsg = in.readLine(); + if (requestMsg == null) break; + sendState(requestMsg); + break; + default: + GameLog.d("LS-NET", "Multiplayer : commande TCP inconnue '" + command + "'"); + break; } } in.close(); } catch (IOException e) { - e.printStackTrace(); + GameLog.e("LS-NET", "Multiplayer : reader TCP interrompu", e); } } }