Skip to content

Commit

Permalink
Add a catch for an error case
Browse files Browse the repository at this point in the history
An error seems to happen for some persons. And they won't see it, cause its only in console. Now this error will cause a popup to happen.
Additional debug-information has been added to console.
  • Loading branch information
Ecconia committed Jun 12, 2020
1 parent a9fc146 commit ac737f9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>de.ecconia.scrapmechanicmapper</groupId>
<artifactId>ScrapMechanicMapper</artifactId>
<version>1</version>
<version>1.1</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
37 changes: 27 additions & 10 deletions src/main/java/de/ecconia/scrapmechanicmapper/AddressToPosition.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.ecconia.scrapmechanicmapper;

import de.ecconia.scrapmechanicmapper.accessor.ProcessWrapper;
import javax.swing.JOptionPane;

public class AddressToPosition extends Thread
{
Expand All @@ -24,22 +25,38 @@ public AddressToPosition(long addressA, long addressB, PositionReceiver receiver
@Override
public void run()
{
System.out.println("Started update thread.");
while(!isInterrupted())
try
{
float a = process.readFloat(addressA);
float b = process.readFloat(addressB);
receiver.updatePosition(a, b);

try
System.out.println("Started update thread.");
while(!isInterrupted())
{
Thread.sleep(500);
float a = process.readFloat(addressA);
float b = process.readFloat(addressB);
receiver.updatePosition(a, b);

try
{
Thread.sleep(500);
}
catch(InterruptedException e)
{
break;
}
}
catch(InterruptedException e)
}
catch(Error e)
{
if(e.getMessage().equals("Invalid memory access"))
{
break;
System.out.println("Cannot access it.");
JOptionPane.showMessageDialog(null, "Cannot read from that address. Start with console and report to developer.");
}
else
{
throw e;
}
}

System.out.println("Stopped updated thread.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ public class ProcessWrapper
public ProcessWrapper(String name)
{
int pid = getProcessId(name);
System.out.println("Pid is: " + pid);
if(pid == 0)
{
System.err.println("Could not find process.");
System.exit(1);
}

process = openProcess(PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION | PROCESS_QUERY_INFORMATION, pid);
System.out.println("Process val: " + process);
}

public String getProcessImageFileName()
Expand Down

0 comments on commit ac737f9

Please sign in to comment.