Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NativeBinaryLoader] Allow loading natives via JME NativeLibraryLoader #48

Closed
Ali-RS opened this issue Mar 24, 2023 · 4 comments · Fixed by #50
Closed

[NativeBinaryLoader] Allow loading natives via JME NativeLibraryLoader #48

Ali-RS opened this issue Mar 24, 2023 · 4 comments · Fixed by #50
Labels
core Concerning API core code enhancement New feature or request
Milestone

Comments

@Ali-RS
Copy link
Contributor

Ali-RS commented Mar 24, 2023

It would be nice to add an option to be able to extract and load natives via JME NativeLibraryLoader. By default, JME (in the master branch) will export to System.getProperty("java.io.tmpdir") instead of extracting to the working directory (user.dir) if no custom extraction folder is specified.

@pavly-gerges pavly-gerges added enhancement New feature or request core Concerning API core code labels Mar 24, 2023
@pavly-gerges pavly-gerges added this to the API-Core-Code milestone Mar 24, 2023
@pavly-gerges pavly-gerges changed the title Allow loading via natives via JME NativeLibraryLoader [NativeBinaryLoader] Allow loading via natives via JME NativeLibraryLoader Mar 24, 2023
@pavly-gerges pavly-gerges pinned this issue Mar 24, 2023
@pavly-gerges
Copy link
Member

This could be managed by creating a static Boolean flag NativeBinaryLoader.isAutoLoad() and it's setter method.

Notice, the flag should be true by default; because disabling the extraction process by default will break the test CI/CD workflow, so you will have to set this manually when implementing in jMonkeyEngine, before calling the NativeBufferAllocator.<cinit> (the static initializer).

If you agree on these modifications, please let me know, so I could prepare my schedule to solve this issue.

@pavly-gerges
Copy link
Member

If you also cannot think of a good place to make a call for NativeBinaryLoadr.setAutoLoad(false), please let me know, too.

@Ali-RS
Copy link
Contributor Author

Ali-RS commented Mar 24, 2023

What about using a system property? for example System.getProperty("com.jme3.alloc.librarypath")

NativeBinaryLoader can first check if the librarypath property is set and load it from there otherwise extract it automatically.

Edit:

Never mind, I think using NativeBinaryLoadr.setAutoLoad(false) is fine.

If you also cannot think of a good place to make a call for NativeBinaryLoadr.setAutoLoad(false), please let me know, too.

I think it should be in the class implementing JME BufferAllocator interface. (i.e. LwjglBufferAllocator).

    public class LwjglBufferAllocator implements BufferAllocator {

        static {
              NativeBinaryLoadr.setAutoLoad(false);
              NativeLibraryLoader.load(JmeAlloc);
        }

        @Override
        public void destroyDirectBuffer(Buffer toBeDestroyed) {
            NativeBufferAllocator.releaseDirectByteBuffer(toBeDestroyed);
        }

        @Override
        public ByteBuffer allocate(int size) {
            return NativeBufferAllocator.createDirectByteBuffer(size);
        }
    }

@Ali-RS Ali-RS changed the title [NativeBinaryLoader] Allow loading via natives via JME NativeLibraryLoader [NativeBinaryLoader] Allow loading natives via JME NativeLibraryLoader Mar 24, 2023
@pavly-gerges pavly-gerges linked a pull request Mar 25, 2023 that will close this issue
3 tasks
@pavly-gerges
Copy link
Member

@Ali-RS Feel free to review PR #50.

@pavly-gerges pavly-gerges unpinned this issue Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Concerning API core code enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants