Fix OutOfMemory after enable Log output

This commit is contained in:
khanhduytran0 2020-09-09 13:09:12 +07:00
parent 816c0ad709
commit 42357626cf

View file

@ -108,7 +108,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
private Button[] controlButtons; private Button[] controlButtons;
private File logFile; private File currLogFile, logFile;
private PrintStream logStream; private PrintStream logStream;
/* /*
@ -253,6 +253,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
@Override @Override
public void onCheckedChanged(CompoundButton button, boolean isChecked) public void onCheckedChanged(CompoundButton button, boolean isChecked)
{ {
if (isChecked) Tools.write(currLogFile.getAbsolutePath(), "");
isLogAllow = isChecked; isLogAllow = isChecked;
appendToLog(""); appendToLog("");
} }
@ -645,6 +646,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) { public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) {
LWJGLInputSender.windowWidth = width; LWJGLInputSender.windowWidth = width;
LWJGLInputSender.windowHeight = height; LWJGLInputSender.windowHeight = height;
LWJGLInputSender.sendUpdateWindowSize(width, height);
calculateMcScale(); calculateMcScale();
// TODO: Implement this method for GLFW window size callback // TODO: Implement this method for GLFW window size callback
@ -833,7 +835,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
private FileObserver mLogObserver; private FileObserver mLogObserver;
private void runCraft() throws Throwable { private void runCraft() throws Throwable {
if (Tools.LAUNCH_TYPE != Tools.LTYPE_PROCESS) { if (Tools.LAUNCH_TYPE != Tools.LTYPE_PROCESS) {
final File currLogFile = JREUtils.redirectStdio(true); currLogFile = JREUtils.redirectStdio(true);
// DEPRECATED constructor (String) api 29 // DEPRECATED constructor (String) api 29
mLogObserver = new FileObserver(currLogFile.getAbsolutePath(), FileObserver.MODIFY){ mLogObserver = new FileObserver(currLogFile.getAbsolutePath(), FileObserver.MODIFY){
@Override @Override
@ -923,8 +925,8 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
} }
private void appendToLog(final String text, boolean checkAllow) { private void appendToLog(final String text, boolean checkAllow) {
if (checkAllow && !isLogAllow) return;
logStream.print(text); logStream.print(text);
if (checkAllow && !isLogAllow) return;
textLog.post(new Runnable(){ textLog.post(new Runnable(){
@Override @Override
public void run() { public void run() {