View previous topic :: View next topic |
Author |
Message |
mutable
Joined: 22 Jun 2010 Posts: 87
|
Posted: Fri Sep 02, 2011 2:39 am Post subject: Derelict GL: glGenBuffers generate memory error |
|
|
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 |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
|
Back to top |
|
|
mutable
Joined: 22 Jun 2010 Posts: 87
|
Posted: Sat Sep 03, 2011 12:07 pm Post subject: |
|
|
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 |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Sat Sep 03, 2011 10:27 pm Post subject: |
|
|
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 |
|
|
mutable
Joined: 22 Jun 2010 Posts: 87
|
Posted: Sun Sep 04, 2011 4:38 am Post subject: |
|
|
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 |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Sun Sep 04, 2011 7:07 am Post subject: |
|
|
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 |
|
|
mutable
Joined: 22 Jun 2010 Posts: 87
|
Posted: Mon Sep 05, 2011 1:38 am Post subject: |
|
|
Oh that is embarrassing ._. sorry. Next time i will read and search first. |
|
Back to top |
|
|
ponce
Joined: 12 Nov 2009 Posts: 55
|
|
Back to top |
|
|
|