VK10.VK_VERSION_MAJOR can return negative values

Started by juha, March 16, 2020, 09:38:18

Previous topic - Next topic

juha


This appears to be a minor issue but came up with value range testing:

VK10.VK_VERSION_MAJOR can return negative integer. The assumption is all returned values are positive due to underlying C99 API using unsigned integers.

The following code will return signed value -512 instead of the expected value 512:

System.err.println(VK10.VK_VERSION_MAJOR(0x80000000));

> -512


Assuming we've not misunderstood the intended bit manipulation operations, the (decompiled) implementation of VK_VERSION_MAJOR should use Java's unsigned bit shift operation '>>>' instead of the signed right shift operation '>>':

  public static int VK_VERSION_MAJOR(@NativeType("uint32_t") int version) 
  {
    return version >>> 22;
  }


Or alternatively use bit-wise AND mask to drop the signed bit:

  public static int VK_VERSION_MAJOR(@NativeType("uint32_t") int version) 
  {
    return version >> 22 & 1023;
  }


Given the current code does yield 512 distinct *major* versions, this is probably not a high priority issue for anyone at the moment :-)



spasi

Thanks! This will be fixed in the next 3.2.4 snapshot.