Skip to content

Commit

Permalink
[FIX] Защита от двойного Shutdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaxar163 committed Apr 4, 2020
1 parent 8c4b91f commit b1915a2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,37 @@ private void launcherInit(ClientEngineInitPhase phase)
}
private void exitHandler(ClientExitPhase phase)
{
if(isClosed) return;
isClosed = true;
if (isClosed(true)) return;
if(DiscordRPC.thr != null) DiscordRPC.thr.interrupt();
if(DiscordRPC.lib != null) DiscordRPC.lib.Discord_Shutdown();
if(RequestEventWatcher.INSTANCE != null) Request.service.unregisterEventHandler(RequestEventWatcher.INSTANCE);
}
public static boolean isClosed = false;
private static final Object lock = new Object();
private static volatile boolean isClosed = false;
private void exitByStartClient(ClientProcessBuilderParamsWrittedEvent event)
{
if(isClosed) return;
if (isClosed(true)) return;
try {
isClosed = true;
if(DiscordRPC.thr != null) DiscordRPC.thr.interrupt();
if(DiscordRPC.lib != null) DiscordRPC.lib.Discord_Shutdown();
if(RequestEventWatcher.INSTANCE != null) Request.service.unregisterEventHandler(RequestEventWatcher.INSTANCE);
} catch (Throwable ignored)
{
}
}

/**
* @param flag Set closed to true?
* @return Current closed.
*/
public static boolean isClosed(boolean flag) {
boolean ret;
synchronized(lock) {
ret = isClosed;
if (flag) isClosed = true;
lock.notify();
}
return ret;
}

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void onConfig(String appId, String firstLine, String secondLine, String l
break;
}
}
if(!ClientModule.isClosed)
if(!ClientModule.isClosed(false))
lib.Discord_Shutdown();
}, "RPC");
thr.setDaemon(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ private CacheData getCached(UUID uuid, String username) {
JsonObject property0 = property.getAsJsonObject();
if (property0.get("name").getAsString().equals("textures")) {
byte[] asBytes = Base64.getDecoder().decode(property0.get("value").getAsString());
String asString = new String(asBytes, StandardCharsets.UTF_8);
JsonParser parser = new JsonParser();
texturesProperty = parser.parse(asString).getAsJsonObject();
texturesProperty = JsonParser.parseString(new String(asBytes, StandardCharsets.UTF_8)).getAsJsonObject();
break;
}
}
Expand Down

0 comments on commit b1915a2

Please sign in to comment.