openImplicit

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Fri Apr 21 21:07:44 UTC 2023


Hi Michael,
your segment looks correct - the empty optional just indicates that it's 
an off-heap segment, and that there's no Java array backing it.

The code that calls glGenTextures also looks ok. Unfortunately I'm not 
an expert on macos and OpenGL (although I known that combo is getting 
trickier to run following the push to Metal). Perhaps someone with more 
OpenGL expertize can chime in? (CC'ing Martin Pernollet).

P.S. I believe the cast to (int) is redundant - the JAVA_INT layout 
should be able to drive the correct return type in overload selection. 
Also, if you are using jextract (as it seems looking at the code you 
pasted), I suggest you stick with the C types that jextract generates 
(e.g. C_INT instead of JAVA_INT). It's not the issue here, but some 
types (such as C_LONG) can have a definition which different from 
platform to platform.

Cheers
Maurizio


On 21/04/2023 19:36, Michael Hall wrote:
> Thanks
>
>> On Apr 21, 2023, at 1:14 PM, Maurizio Cimadamore <maurizio.cimadamore at oracle.com> wrote:
>>
>> Yes. The semantics of `SegmentScope.auto()` is the same as that of `MemorySession.openImplicit`.
>>
>> Maurizio
>>
>> On 21/04/2023 19:08, Michael Hall wrote:
>>> Would this be the correct jdk20 change?
>>>
>>> //textureBufferIds = MemorySegment.allocateNative(1 * 4 * 3, SegmentScope.openImplicit());
>>>      textureBufferIds = MemorySegment.allocateNative(1 * 4 * 3, SegmentScope.auto());
> I thought this is all I did that would affect this code. Except for pointing at different OS/X dylib’s.
> But on...
>
>     gl.glGenTextures(1, textureBufferIds);
>      idTexture = (int) textureBufferIds.get(ValueLayout.JAVA_INT, 0);
>
>      Debug.debug(debug, "FBO: Got texture ID : " + idTexture);
>
>
>      // Check errors
>      if (idTexture == 0) {
>        diagnoseError(gl, "texture");
>      }
>
> I get this error…
>
> FBO: texture handle=0 but get no OpenGL error. This may happen if the call was not issued from main thread on macOS
>
> This appears to come down to…
>
>      public static MethodHandle glGenTextures$MH() {
>          return RuntimeHelper.requireNonNull(constants$86.glGenTextures$MH,"glGenTextures");
>      }
>      /**
>       * {@snippet :
>       * void glGenTextures(GLsizei n, GLuint* textures);
>       * }
>       */
>      public static void glGenTextures(int n, MemorySegment textures) {
>          var mh$ = glGenTextures$MH();
>          try {
>          	System.out.println("glut_h_3: glGenTextures n = " + n + " textures = " + textures + " mh$ = " + mh$);
>              mh$.invokeExact(n, textures);
>          } catch (Throwable ex$) {
>              throw new AssertionError("should not reach here", ex$);
>          }
>      }
>      public static MethodHandle glGetBooleanv$MH() {
>          return RuntimeHelper.requireNonNull(constants$86.glGetBooleanv$MH,"glGetBooleanv");
>      }
>
> Where the println shows…
> glut_h_3: glGenTextures n = 1 textures = MemorySegment{ array: Optional.empty address:105553149374912 limit: 12 } mh$ = MethodHandle(int,MemorySegment)void
>
> Does the empty address indicate a problem or does this still appear correct and my replaced native code is the probable problem?
>


More information about the panama-dev mailing list