Thread overview
DerelictGL3 glGenBuffers segmentation fault.
Dec 24
Kevin
Dec 24
Kevin
Dec 24
Kevin
Dec 24
Kevin
December 24
I'm working a library with DerelictGL3.
using branch 2.0

import derelict.opengl;
import std.stdio : writeln;

struct VertexBuffer
{
    GLuint vbo;
    GLsizei count;

    this(GLsizei n)
    {
        writeln("creating vbo");
        glGenBuffers(n, &vbo);
        writeln("created vbo");
        count = n;
        writeln("exiting vbo");
    }

    // more code
}

When I import my library into my program.
glGenBuffers segmentation fault.

When I copy VertexBuffer into main code. It works fine.
Why am I getting segmentation fault from library ?
December 24
On Sunday, 24 December 2017 at 00:58:25 UTC, Kevin wrote:


>
> When I import my library into my program.
> glGenBuffers segmentation fault.
>
> When I copy VertexBuffer into main code. It works fine.
> Why am I getting segmentation fault from library ?

Need more info than this. Some code that reproduces the issue would be helpful. Also, what do you mean by "import my library"?


December 24
On Sunday, 24 December 2017 at 01:42:58 UTC, Mike Parker wrote:

> Need more info than this. Some code that reproduces the issue would be helpful. Also, what do you mean by "import my library"?

I making a simple static library.
For I can go through Opengl tutorials again.
Need to refresh my memory.

reproduce error code here.
https://github.com/Windspar/Derelict-Testing
Yes I know there other problems.

December 24
On Sunday, 24 December 2017 at 03:00:16 UTC, Kevin wrote:
> On Sunday, 24 December 2017 at 01:42:58 UTC, Mike Parker wrote:

I've found the problem. But first...

> I making a simple static library.

I don't see a static library anywhere. You weren't "importing a static library", something which isn't possible in D anyway. You import modules, not libraries.

The reason it worked in your main source file (cube.d) and not in your buffers module is this line:


mixin glFreeFuncs!(GLVersion.gl33);

You have that in cube.d, but in buffers.d you have this:

import derelict.opengl;


If you are going to use glFreeFuncs like this, you can't import opengl that way. As per the DerelictGL3 documentation [1], the simplest way to make this work is to implement a module that publicly imports derelict.opengl and declares the mixin, then import that module elsewehre. So the first step to making your code work is this:

```
module mygl;

public import derelict.opengl;
mixin glFreeFuncs!(GLVersion.GL33);
```

That's not all, though. The documentation also explicitly says you have to define the DerelictGL3_CustomFreeFuncs version when you compile. So add this to your dub.json:

```
"versions": [
   "DerelictGL3_CustomFreeFuncs"
],
```

That should at least get you compiling. But your dependency declarations have a couple of issues that need fixing. Currently, you have this:

```
"derelict-sdl2": "~>3.0",
"derelict-gl3": "~2.0",
```

Your sdl2 dependency is syntactically correct, but what it says is that you're happy with any version of DerelictSDL2 from 3.0.x to 3.9.x, inclusive. The result is that you're actually getting version 3.1.0-alpha.3. In the near future, I'll be updating for SDL 2.0.7 and will add a new 3.2.0-alpha.1 version. If you run `dub upgrade` at that point, you'll get that version. That's a bad idea!

What you want to do is to specify the full version, major.minor.path, 3.0.0. And, since there is a 3.0.0-beta and not a 3.0.0, you'll need to append -beta.

The same applies to your gl3 dependency, but you have another problem there. The syntax is incorrect: ~2.0 instead of ~>2.0. ~foo tells dub to look for a git branch with the name "foo" -- and it's deprecated syntax. Since there happens to be a branch in the DerelictGL3 github repo named "2.0", that's what you're actually getting.

So you should update your dependencies to look like this:

```
"derelict-sdl2": "~>3.0.0-beta",
"derelict-gl3": "~>2.0.0-beta",
```

Be sure to delete your dub.selections.json after editing and before you rebuild.

With these, you'll be compiling and properly upgrading in the future if you need to.

[1] http://derelictorg.github.io/packages/gl3/
December 24
On Sunday, 24 December 2017 at 05:23:12 UTC, Mike Parker wrote:

>
> If you are going to use glFreeFuncs like this, you can't import opengl that way. As per the DerelictGL3 documentation [1], the simplest way to make this work is to implement a module that publicly imports derelict.opengl and declares the mixin, then import that module elsewehre.

In case that wasn't clear, make sure to replace every current instance of `import derelict.opengl` with `import mygl`, or whatever you happen to name the module.
December 24
Thanks. That help but know my buffers doesn't recognize opengl types.

I created mygl and import it to all files. Updated code on github.
source/buffers.d(6,12): Error: undefined identifier GLuint, did you mean alias GLuint64?
source/buffers.d(7,13): Error: undefined identifier GLsizei
and more.

Did I put "DerelictGL3_CustomFreeFuncs" in the right place ?
json file
    "name": "cube",
    "targetType": "executable",
    "mainSourceFile": "source/cube.d",
    "dependencies": {
    "derelict-sdl2": "~>3.0.0-beta",
    "derelict-gl3": "~>2.0.0-beta",
    "gl3n": "~>1.3.1",
    },
    "versions": [ "DerelictGL3_CustomFreeFuncs" ],
December 24
On Sunday, 24 December 2017 at 14:48:20 UTC, Kevin wrote:
> Thanks. That help but know my buffers doesn't recognize opengl types.
>
> I created mygl and import it to all files. Updated code on github.
> source/buffers.d(6,12): Error: undefined identifier GLuint, did you mean alias GLuint64?
> source/buffers.d(7,13): Error: undefined identifier GLsizei
> and more.

In mygl.d, your import of derelict.opengl needs to be public:

module mygl;
public import derelict.opengl;
mixin glFreeFuncs!(GLVersion.gl33);

>
> Did I put "DerelictGL3_CustomFreeFuncs" in the right place ?
> json file
>     "name": "cube",
>     "targetType": "executable",
>     "mainSourceFile": "source/cube.d",
>     "dependencies": {
>     "derelict-sdl2": "~>3.0.0-beta",
>     "derelict-gl3": "~>2.0.0-beta",
>     "gl3n": "~>1.3.1",
>     },
>     "versions": [ "DerelictGL3_CustomFreeFuncs" ],

It doesn't matter where it goes, as long as it's on its own line.

December 24
On Sunday, 24 December 2017 at 16:27:11 UTC, Mike Parker wrote:
> On Sunday, 24 December 2017 at 14:48:20 UTC, Kevin wrote:
>> [...]
>
> In mygl.d, your import of derelict.opengl needs to be public:
>
> module mygl;
> public import derelict.opengl;
> mixin glFreeFuncs!(GLVersion.gl33);
>
>>     [...]
>
> It doesn't matter where it goes, as long as it's on its own line.

Thanks You.