Closed Ali-RS closed 1 year ago
What happens if a user routinely runs applications that use different versions of JME? (like me)
The application should still work as before. It will just extract and load natives from a different place.
It seemed like you would be extracting all of the natives to the same place instead of the application-specific location.
...so if I were running my mapper tool in one window and tried to run jmec in another window then one of those applications might be corrupting the native libraries of another.
Ah, now I see what you mean.
Probably that is why NativeLibraryLoader generates a native hash for naming the directory when extracting to UserCache... not sure thought.
* to prevent collisions, a special subfolder is used
* called natives_<hash> where <hash>
* is computed automatically as the XOR of the classpath hash code
* and the last modified date of this class.
See here
Does this settle the concern? or do you suggest a different solution?
By the way, it is also possible to specify a custom location
I also looked at LWJGL3 and from what I understand, when loading, it locks the file using java FileChannel and releases it after loading. So if another app tries to load it at the same time it will wait for the lock to release before loading.
See
and before loading, it checks the file CRC hash with the one in the jar file, and if they do not match, it extract the native file again overwriting the old one. In JME we check this by comparing the last modified date of files.
So if another app corrupts the native file such that its CRC hash (in JME the last modified date) does not match it will always be replaced by a freshly extracted one.
This means we may not need to do the below step if we make use of file locks.
* to prevent collisions, a special subfolder is used * called natives_<hash> where <hash> * is computed automatically as the XOR of the classpath hash code * and the last modified date of this class.
Please let me know what do you think
Instead of the working directory it extracts to the system temp directory retrieved by System.getProperty("java.io.tmpdir")
if no custom extraction folder is specified.
The directory structure is like below
<java.io.tmpdir>/jme3/natives-<hash> // hash is computed automatically for each app to prevent collisions
We should omit the check for "working directory" step above.