UnsatisfiedLinkError Libgdx Desktop - java

I am running into issues with LibGDX on Desktop. I keep getting the following error when trying to launch the application:
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.badlogic.gdx.utils.BufferUtils.newDisposableByteBuffer(I)Ljava/nio/ByteBuffer;
at com.badlogic.gdx.utils.BufferUtils.newDisposableByteBuffer(Native Method)
at com.badlogic.gdx.utils.BufferUtils.newUnsafeByteBuffer(BufferUtils.java:288)
at com.badlogic.gdx.graphics.glutils.VertexArray.<init>(VertexArray.java:62)
at com.badlogic.gdx.graphics.glutils.VertexArray.<init>(VertexArray.java:53)
at com.badlogic.gdx.graphics.Mesh.<init>(Mesh.java:148)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:173)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:142)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:121)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:115)
I have the following libraries added to my project:
gdx.jar
gdx-sources.jar
gdx-natives.jar
gdx-backend-lwjgl.jar
gdx-backend-lwjgl-natives.jar
Am I missing something?
I have searched high and low, but everything I find is for Android and tells me to add the .so libs from the arm folders to my project, but that doesn't make sense to me for a desktop project on wintel platform.

I'd advise you to setup your projects with this GUI. It should provide you with a valid setup for all platforms. You may also use the latest nightly builds and check if the problem still occurs. The problem might be that the native libraries do not match the other jars.
Another problem might be that you instantiate a SpriteBatch (or something else which internally uses a SpriteBatch) too early (looked a bit like this in the stacktrace). For example statically like this:
private static SpriteBatch batch = new SpriteBatch();
This won't work, since libgdx wasn't setup correctly at this point in time. Instead, create such things in the create/show methods of your game.

Use the following main method body to launch the object:
static public void main(String[] args) throws Exception {
// SkeletonViewer.args = args;
String os = System.getProperty("os.name");
float dpiScale = 1;
if (os.contains("Windows")) {
dpiScale = Toolkit.getDefaultToolkit().
getScreenResolution() / 96f;
}
if (os.contains("OS X")) {
Object object = Toolkit.getDefaultToolkit().getDesktopProperty(
"apple.awt.contentScaleFactor");
if (object instanceof Float && ((Float) object).intValue() >= 2) {
dpiScale = 2;
}
}
if (dpiScale >= 2.0f) {
uiScale = 2;
}
LwjglApplicationConfiguration.disableAudio = true;
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.width = (int) (800 * uiScale);
config.height = (int) (600 * uiScale);
config.title = "Skeleton Viewer";
config.allowSoftwareMode = true;
config.samples = 2;
new LwjglApplication(new SampleApplication(), config);
}

Related

How can I obtain relevant params, classes, and methods from a .groovy script from Java?

I have a Java plugin for a larger application that does image analysis using the ImageJ library. One client who switched to our software has been using Groovy scripts to define specific rules and parameters for when they perform the analysis in ImageJ. They would like our software to be able to accept the Groovy scripts as well, as they'll be working within our GUI as well as ImageJ.
They will provide a written script.groovy to the plugin, but I won't always know exactly what parameters, methods, and classes are present and what changes to the logic are in the .groovy file.
I've been looking into the GroovyClassLoader documentation, and after referencing Groovy in Action, 2nd Edition I have a better idea of how to create and send bindings and whatnot but I can't figure out where to start writing the logic for interpreting the contents of a static Groovy file. An ideal solution would be the user having one script that works in both programs, and my plugin determines what is relevant.
Is there any way to parse out individual parts of a Groovy file so that I might map them to our parameters and change the Java plugin's behavior accordingly?
Edit: Context
Our software performs real-time image analysis on stained tissue slides. Some of our users also use "Program X" within its GUI to perform analysis on images that have already been taken. The Java plugin accesses the logic from the other program, allowing our users to use features they're familiar with in real-time.
The Groovy script file.groovy that the user gives to Program X has some functions that feed data to the UI portions of the software that we don't need. I'd like to only parse our relevant portions of the script.
Edit: Sample File, and what I'd like to parse:
The .groovy file begins with some parameters, which are no use to me, as well as some methods for defining image background, also no use as my program does this automatically, where "Program X" does not:
/* imports */
//PARAMETER AREA//
//PARAMETERS FOR IMAGES WITH UM//
double requested_pixel_size = 0.5
double background_radius = 8
double median_filter_radius = 0
double sigma = 1.5
double minimum_area = 10
double maximum_area = 400
double threshold = 0.1
//PARAMETER AREA ENDS//
def openingReconstruction(final ImageProcessor ip, final ImageProcessor ipBackground, final double radius, final double maxBackground) {
final RankFilters rf = new RankFilters()
ipBackground.setRoi(ip.getRoi())
rf.rank(ipBackground, radius, RankFilters.MIN)
ByteProcessor bpMask = null
if (!Double.isNaN(maxBackground) && maxBackground > 0) {
int w = ip.getWidth()
int h = ip.getHeight()
for (int i = 0; i < w * h; i++) {
if (ipBackground.getf(i) > maxBackground) {
if (bpMask == null)
bpMask = new ByteProcessor(w, h)
bpMask.setf(i, 1f)
}
}
if (bpMask != null) {
rf.rank(bpMask, radius * 2, RankFilters.MAX)
for (int i = 0; i < w * h; i++) {
if (bpMask.getf(i) != 0f) {
ipBackground.setf(i, Float.NEGATIVE_INFINITY)
}
}
}
}
Then there are some area which actually enhance our program, and I need to be able to implement:
def detect(double key_value, PathObject parentObject, int Choose_detection_image, ParameterList params) {
def viewer = QPEx.getCurrentViewer()
ImageData<BufferedImage> imageData = viewer.getImageData()
println("Program starts.....")
The above code snippet will eventually call a modified version of the detection class which I need:
detect(key_value, parentObject, Choose_detection_image, params)
class WatershedCellDetection2 {
protected ObjectDetector<BufferedImage> createDetector(ImageData<BufferedImage> imageData, ParameterList params, double key_value) {
ObjectDetector<BufferedImage> detector = new NewCellDetector(key_value)
//insert the key_value in original detector.
return new DetectorWrapper<>(detector)
}
There are a few overloaded methods and other versions of the WatershedCellDetection that are used depending on what parameters are present, but as long as I know how to parse out one I can determine which one is best for each scenario.
There is a lot of code built into the functions that do things like update the help text in the GUI of "Program X" that are irrelevant to my program's UI since this is all interacting with a Java plugin of a C# program.

Task Manager Blocks Java Mouse Mover Program

I've quickly programmed a java program that randomly moves the cursor to prank my mate. Everything works perfectly except that when Task Manager is the current active window, the cursor doesn't move. It works fine when other applications are active. My questions are: What is causing this and if possible, how do i fix it. Here's my code(i know it's messy.):
Robot rob = new Robot();
while (true) {
PointerInfo pointer = MouseInfo.getPointerInfo();
Point point = pointer.getLocation();
int x = (int) point.getX();
int y = (int) point.getY();
int xd = getRandomDirection();
int yd = getRandomDirection();
rob.mouseMove(x+xd, y+yd);
}
private static int getRandomDirection() {
Random ran = new Random();
float ran1 = ran.nextFloat();
if(ran1 > 0.5){
return 1;
}else{
return -1;
}
}
I found the answer. Simply it is a rule in the newer versions of windows that a program that is not "run as admin" can't control over an admin-run program, e.g task manager. The simple solution was enabling the little checkbox on the program in windows with "rightclick" > "properties" > "Compatibility" > "Run as admin" or simply manually running as admin every time with a simple rightclick.

LibGDX: low fps while running multiple instances

I've been playing with libGDX, because I want to develop a multiplayer game with my friend. My recent problem did come up while testing the communication with multiple clients. I run all the clients and the server from one computer. If I run 'n' clients, all the clients run on exactly 60/'n' fps. Why?
The source code of the project is available at: http://github.com/FBalazs/Yellow
The game loop that libgdx uses by default renders at a fixed rate I find it to be about 60fps if you are running on desktop you can set the foreground and background FPS in the desktop application main method.
public class Main {
public static void main(String[] args) {
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "Game Name";
cfg.fullscreen = false;
cfg.vSyncEnabled = false;
cfg.foregroundFPS = 120; // Change the FPS
cfg.width = 1280;
cfg.height = 720;
new LwjglApplication(new MyGdxGame(), cfg);
}
I believe you can also use Continuous & non continuous rendering but I have not tried it as of yet.

how do you add images to the project directory in eclipse?

I have a program that runs and doesnt throw a runtime error in eclipse which should set up an image to a JButton at the end of the program as the result but the image is never put on to the button. The program worked fine in DrJava but I transferred to eclipse in order to make a jar file.
I saw in another question posted that someone had a similar problem that said the images should be put into the project directory not the src directory but it didnt explain how to actually fix the problem... im new to eclipse so if someone could help me out id appreciate it thanks.
here is how the images are set up in my code:
public void tempSelection70 (int fRate, int wbTemp, int rcTons, int a, int r)
{
for (int model = 0; model < 7; model++)
{
MyArray y = new MyArray(tons70FCharts[model], "t");
int[][] x = y.getArray();
int t = x[a][r];
if (rcTons == t)
{
tableButton = new JButton(new ImageIcon(tablesFor70[model], tablesFor70[model]));
break;
}
else
{
tableButton = new JButton(new ImageIcon("CANNOT_FIND_MODEL.GIF", "SCROLL"));
}
}
for (int model = 0; model < 7; model++)
{
MyArray y = new MyArray(flow70FCharts[model], "f");
int[][] x = y.getArray();
int t = x[a][r];
if (fRate == t)
{
tableButton = new JButton(new ImageIcon(tablesFor70[model], tablesFor70[model]));
break;
}
else
{
tableButton = new JButton(new ImageIcon("CANNOT_FIND_MODEL.GIF", "SCROLL"));
}
}
}
You're passing a file name as argument. I guess this file name is a relative file name. So the file is relative to the directory from which your IDE launches the java command to execute your application: the working directory.
This directory can be changed from the run configuration in Eclipse, under the tab "Arguments". But this is probably not what you want. The icons should certainly be bundled with your application, and loaded with the class loader. Put them under a package in your source folder. Eclipse will copy them to the output directory, along with the compiled classes. And if you generate a jhar for your app, they will be bundled in the jar with your classes. Once this is done, you just have to use the constructor taking a URL as argument, and pass
SomeClassOfYourApp.getResource("/the/package/of/the/image.png")
as this URL argument.
This will allow you to bundle the icons with the app easily, and will load the icons whatever the working directory is.

Java is reading old input files, not new ones

I have some java code which reads text files, adds the contents to a vector and then prints these points to screen using a graph windower.
I have three pointdata.txt files, pointdata1.txt, pointdata2.txt and pointdata3.txt.
The problem i am having is that, even when i change the input file in my driver to pointdata1 or pointdata2, it still runs for pointdata3. I have ensured that there are no occurences of pointdata3 anywhere else in the code. It only appears twice, but i have made sure it is the same.
I have checked the files themselves, they are different. Checked and checked and checked the pathnames, they are different!
Even when i comment out every System.out.println() in the entire code, it still prints everything!
It is asif the code is no longer refereing the the text files, or even running, eclipse just keeps printing what was previously added to the viewport?
Here is the code from my driver:
import java.util.*;
public class PointDriver {
private PointField pointfield;
// testing
public void doAllTests() throws Exception{
this.test1();
this.test2();
}
// Display all points in the file
public void test1() throws Exception{
SimpleIO sIO = new SimpleIO();
System.out.println("Contents of Point File: ");
sIO.displayFile("pointdata1.txt");
//sIO.displayFile("pointdata2.txt");
//sIO.displayFile("pointdata3.txt");
System.out.println();
}
// Load points from a file into a vector and echo them back to the screen
// This uses the StringTokenizer to split the lines into two Strings, then
// uses the Point class to assign the two Strings to x,y double variables
// which form Points. Within the same loop, the points are also displayed
// in a window using the Graph Window class. Maximum x and y values are used
// to determine the dimensions of the GraphWindow, adding 10 units to each
// value to provide a border.
public void test2() throws Exception{
System.out.println("Contents of Point File: ");
System.out.println();
System.out.println("Points are Displayed in a Graph Window");
System.out.println();
Vector lines;
lines = pointfield.getlines("pointdata1.txt");
//lines = pointfield.getlines("pointdata2.txt");
//lines = pointfield.getlines("pointdata3.txt");
Iterator IT;
IT = lines.iterator();
Vector v;
v = new Vector();
double maxX, maxY;
PointField pointfield;
pointfield = new PointField();
GraphWindow gw;
gw = new GraphWindow();
while (IT.hasNext()) {
StringTokenizer st;
String ID = (String)IT.next();
st = new StringTokenizer(ID);
double x = Double.parseDouble(st.nextToken());
double y = Double.parseDouble(st.nextToken());
Point p;
p = new Point(x,y);
v.addElement(p);
int i = v.size();
System.out.println("Point ID: " +i+ " X: "+x+", Y: "+y);
gw.plotPoint(x, y);
}
this.pointfield = new PointField(v);
maxX = this.pointfield.findMaxXPoint();
maxY = this.pointfield.findMaxYPoint();
int width = (int)maxX + 10;
int height = (int)maxY + 10;
gw.setMap(width, height);
}
// Short main method to kick of all tests sequence in doAllTests method
public static void main(String[] args) throws Exception {
PointFieldDriver pfd;
pfd = new PointFieldDriver();
pfd.doAllTests();
}
}
It looks like Eclipse is running an old version of your class file. I'm gathering this as you said that you commented out the printlns, but the output is still displaying.
A few things to check:
In the menu, make sure that Project > Build Automatically is set. If that isn't set, set it, and your problem should be solved.
See whether the timestamp on your class file is changing when you change the source. If it isn't, then Eclipse isn't recompiling it for some reason. You can find the class file probably under the bin folder (if you are using the Eclipse project defaults).
If you find the timestamp is old, try removing the bin folder from outside of Eclipse. Next, right-click on the project and select refresh. Finally, select Project > Clean. This should cause the code to be recompiled into a new class file.

Categories

Resources