FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Derelict GL: glGenBuffers generate memory error

 
Post new topic   Reply to topic     Forum Index -> Derelict
View previous topic :: View next topic  
Author Message
mutable



Joined: 22 Jun 2010
Posts: 87

PostPosted: Fri Sep 02, 2011 2:39 am    Post subject: Derelict GL: glGenBuffers generate memory error Reply with quote

Any time i called
Code:
GLuint vboId; glGenBuffers(1, &vboId);
i earn an access violation and a memory leak. How is that possible?
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Sat Sep 03, 2011 3:15 am    Post subject: Reply with quote

I have no idea. Have you tried any debugging at all?
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
mutable



Joined: 22 Jun 2010
Posts: 87

PostPosted: Sat Sep 03, 2011 12:07 pm    Post subject: Reply with quote

Not yet, but i earn the error every time i called glGenBuffers, so i thought that it must be a problem of derelict.
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Sat Sep 03, 2011 10:27 pm    Post subject: Reply with quote

Without looking at any code, it's impossible to do anything other than guess.

An Access Violation usually means you've tried to access a null variable. Since all of the function declarations in Derelict are function pointers, the first thing I would suspect is that glGenBuffers is not loaded, which could be the case depending on how you initialized DerelictGL. I would need to see your initialization code to verify that.

But there are other possibilities as well. And you have given no useful information at all to work from. When reporting problems here, it's really beneficial to give as much information as possible if you aren't able to debug it yourself. A minimal test case, compiler and version, platform, and so on.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
mutable



Joined: 22 Jun 2010
Posts: 87

PostPosted: Sun Sep 04, 2011 4:38 am    Post subject: Reply with quote

I have this code
Code:

import std.stdio;

public import derelict.sdl.sdl;
public import derelict.sdl.image;

public import derelict.opengl.gl;
public import derelict.opengl.glu;


static this() {
    DerelictSDL.load();
    DerelictSDLImage.load();

    DerelictGL.load();
    DerelictGLU.load();

    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
      throw new Exception("Dgame konnte nicht gestartet werden.");
   }
}

static ~this() {
    SDL_Quit();

    DerelictGL.unload();
    DerelictGLU.unload();

    DerelictSDLImage.unload();
    DerelictSDL.unload();
}

void setup_openGL(uint w, uint h) {
    glClearColor(1, 1, 1, 0);

    glViewport(0, 0, w, h);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // important
    gluOrtho2D(0, w, h, 0);

    glEnable(GL_TEXTURE_2D);

    // alpha blending
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_GREATER, 0.1);

    glEnable(GL_CULL_FACE);
    glCullFace(GL_FRONT);
}

void main() {
    setup_openGL(480, 640);

    GLuint vboId;
    glGenBuffers(1, &vboId);
}

And i get this error:
Quote:

object.Error: Access Violation
----------------
466AA0
466917
43263B
432237
47F431
----------------
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Sun Sep 04, 2011 7:07 am    Post subject: Reply with quote

Thank you. Now I can see the problem.

The reason you are getting the access violation is because you never loaded OpenGL versions greater than 1.1. DerelictGL.load only loads up to 1.1. glGenBuffers is an OpenGL 1.5 function. Since you never loaded it, the function pointer is null. You can load functions from OpenGL 1.2 - 2.1 with DerelictGL.loadClassicVersions (or DerelictGL.loadExtendedVersions). See the sticky thread at the top of this forum called How to Use DerelictGL in Derelict2

But you have another major problem. I see the call to SDL_Init, and I don't see any call to SDL_SetVideoMode. I assume you have done so somewhere else in your code and just didn't paste it here. But I want to be thorough. You need to create an OpenGL context before loading the extended versions. Otherwise, loading will fail.

So what you need to do is set up an OpenGL context and create a Window with SDL (see this example). Then, after that, make a call to DerelictGL.loadClassicVersions(). I suggest you decide on a minimum OpenGL version you want to use and pass that as a parameter. For example, if you want to require OpenGL 2.0,

Code:

DerelictGL.loadClassicVersions(GLVersion.GL20);


Then, if the user's graphics card does not support at least OpenGL 2.0, the load will fail and an exception will be thrown.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
mutable



Joined: 22 Jun 2010
Posts: 87

PostPosted: Mon Sep 05, 2011 1:38 am    Post subject: Reply with quote

Oh that is embarrassing ._. sorry. Next time i will read and search first.
Back to top
View user's profile Send private message
ponce



Joined: 12 Nov 2009
Posts: 55

PostPosted: Wed Oct 26, 2011 3:40 pm    Post subject: Reply with quote

Another problem: you cannot call such OpenGL functions without creating a context first.

http://www.libsdl.org/docs/html/sdlsetvideomode.html will create and select one for you provided you pass the SDL_OPENGL flag.
_________________
@p0unce | gamesfrommars
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Derelict All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group