Hello Guest

Why are native methods unsafe?

  • 2 Replies
  • 1636 Views
Why are native methods unsafe?
« on: February 18, 2017, 13:55:34 »
In the attached picture, why call glCompileShader(int shader) method instead of nglCompileShader(int shader). And in the documentation why calling the latter is unsafe. I just want to understand why?

*

Offline spasi

  • *****
  • 2043
    • WebHotelier
Re: Why are native methods unsafe?
« Reply #1 on: February 18, 2017, 16:29:00 »
This was a side-effect of the new thread-local implementation of OpenGL and OpenGL ES calls in LWJGL 3.1.1. The code generator has been taught the new scheme and it now produces cleaner code. This is what the code looks like in the latest 3.1.2 snapshot. (I just noticed the SDK link is missing, will fix)

In general, LWJGL produces normal and "unsafe" methods when there's something special that LWJGL does to make calling the native function easier/safer/etc. For example, normal LWJGL methods accept nio buffers, while the corresponding unsafe methods accept raw pointer values. In glCompileShader's case, there's nothing special to be done, so there shouldn't be an unsafe version.

Re: Why are native methods unsafe?
« Reply #2 on: August 21, 2018, 19:55:02 »
In general, LWJGL produces normal and "unsafe" methods when there's something special that LWJGL does to make calling the native function easier/safer/etc. For example, normal LWJGL methods to use dbol for bulking cycles accept nio buffers, while the corresponding unsafe methods accept raw pointer values. In glCompileShader's case, there's nothing special to be done, so there shouldn't be an unsafe version.

Thanks for the clear and concise explanation about why and when the native methods are unsafe. I was looking for information about it.
« Last Edit: November 08, 2018, 16:43:29 by JohnEvangelista »