LwjglContext (in jme3-lwjgl3 module) specifies its own implementation of buffer allocator to be used by BufferAllocatorFactory by setting PROPERTY_BUFFER_ALLOCATOR_IMPLEMENTATION property in this static code block:
the issue is that sometimes this property gets ignored by BufferAllocatorFactory and a ReflectionAllocator is created instead. That is because BufferAllocatorFactory.create() method sometimes is called before the LwjglContext sets the new property. Inside the BufferUtils class:
Sometimes the order of these static code execution is different, e.g the one in the BufferUtils runs before the LwjglContext, which will cause BufferAllocator allocator to get initialized with Reflectionallocator and bypass the LWJGL3 allocator.
2 possible fixes are suggested for this issue:
So should the current buffer allocators get renamed to NativeBufferAllocator?
For example, jme3-lwjgl3 has 2 native buffer allocators, LWJGLBufferAllocator and ConcurrentLWJGLBufferAllocator which extends LWJGLBufferAllocator. ConcurrentLWJGLBufferAllocator is used by default.
How do you want to rename these classes?
Probably we should have NativeBufferAllocator as a third class that uses either LWJGLBufferAllocator or ConcurrentLWJGLBufferAllocator(default) depending on a system property that is passed from the command line
Then BufferAllocatorFactory will first check for a user-specified property using System.getProperty(PROPERTY_BUFFER_ALLOCATOR_IMPLEMENTATION) and if nothing is specified then it will check the bufferallocator.cfg file.
Well in the future, we might add other allocators. For example, the JEP 419: Foreign Function & Memory API will introduce a new API that we can use to release direct byte buffer memory purely in Java so then using the name NativeBufferAllocator for this would not make sense also if we decided to make it the default for one of the backends. But using a config file we can just replace the string to switch the allocator.