vannaka / Motion_Profile_Generator

Generate paths to follow with a robot.
MIT License
94 stars 28 forks source link

Pathfinder JNI blindly assumes Windows, UnsatisfiedLinkErrors on Linux #28

Closed Redrield closed 6 years ago

Redrield commented 6 years ago

After trying and failing to run this program on Arch Linux, I decided to analyze the problems I was seeing.

When the Pathfinder that is being included in the jar attempts to set up JNI, it blindly extracts a dll file and attempts to load that. The decompiled code looks like so

    static {
        if (!(PathfinderJNI.libLoaded = false)) {
            try {
                NativeUtils.loadLibraryFromJar("/any64/pathfinderjava.dll");
            }
            catch (Exception e) {
                e.printStackTrace();
            }
            PathfinderJNI.libLoaded = true;
        }
    }

This code is divergent from the rest of Pathfinder, where the implementation looks like so

This bad code also means that the application will not work if ran outside of windows, as the native libs that Pathfinder requires to function will not be loaded.

This is a critical bug, because it means that anyone outside of Windows will be unable to use this application.

vannaka commented 6 years ago

We're just using an older version of the Pathfinder jar. The newer version clearly fixes this issue. I'll mess with the new jar, hopefully it doesn't break anything.

bdaroz commented 6 years ago

Yep, same problem on MacOS as well...

Redrield commented 6 years ago

A workaround that I found is that you can compile Pathfinder and Pathfinder-Java native libs, and copy them to somewhere on your path (/usr/local/lib for me), then recompile this with Pathfinder-Java from Jaci's repo. It'll just load libpathfinderjava which will hit the stuff you just compiled.

vannaka commented 6 years ago

@Redrield Is the code above decompiled from the Pathfinder-Java-1.8.jar included with Motion_Profile_Generator_3.0.0? The reason I ask is because the above code uses NativeUtils.loadLibraryFromJar() from here but I've been looking through the Pathfinder-java codebase and cannot find any mention of the above code. I have no idea where your decompiled code came from!? The included Pathfinder library is unmodified.

Redrield commented 6 years ago

Yes, that's out of Motion_Profile_Generator_3.0.0. I decompiled it with Luyten and that's what shows up out of PathfinderJNI. Like I said this is confusing because it's completely divergent from the rest of pathfinder.

PotentialIngenuity commented 6 years ago

@Redrield We have a build working that detects which OS you're using and loads the correct lib from the jar. I have tested it on Ubuntu 18.04. Check out the Linux_Support branch if you want to try it.

Redrield commented 6 years ago

@blake1029384756 I would try it but it seems there is no compiled version of it of that branch, and I have no interest in downloading eclipse (ant from the command line does not work). Is there any other way that I could get my hands on it?

PotentialIngenuity commented 6 years ago

@Redrield Here you go!

Redrield commented 6 years ago

From my tests before (which consisted of adding 2 waypoints and seeing if it draws the path correctly), this is working. This was without libpathfinder{java}.so on my path.

vannaka commented 6 years ago

Awesome

gftabor commented 6 years ago

Is there a reason it isn't all done as a git submodule and links directly with the Pathfinder source? That way all users would build from source on their own machine? It would also ensure the newest version of Pathfinder is always used. Finally it would point users to the proper location for bug reports/ crediting the original author.

vannaka commented 6 years ago

@gftabor We had talked about doing that but for one reason or another never got around to it. If you'd like you can submit a PR and I'll merge it. As a side note, we've had to make changes to the Pathfinder source to load its libs from inside the jar.

PotentialIngenuity commented 6 years ago

We have added the required libs and dynamically load them Added in this commit

PotentialIngenuity commented 6 years ago

@gftabor Pathfinder only compiles a jar for the machine you are on. So in order to support mac, linux and windows we have to compile on each machine separately. To get around this we would need a cross compiler which I dont know how to do. That is why we dont have Pathfinder as a submodule.