-
January 10th, 2018, 08:32 AM
#1
[RESOLVED] Exception thrown at 0x00000000 when using DLL.
I wrote a function that compile vertex shader and fragment shader of GLSL and return a shader program ID.If I put that function code directly a program it works fine.The problem is when I compile that code as a DLL and use it in a program, the dll throw an exception.Exception thrown at 0x00000000 in Triangle.exe: 0xC0000005: Access violation executing location 0x00000000.
Here's the code;
Code:
#include "stdafx.h"
GLuint createShaderProgram(const char* vertex_file, const char* fragment_file)
{
using namespace std;
fstream vertexFile;
vertexFile.open(vertex_file, ios::in);
string inputVertexCode;
string vertexCode_str;
ostringstream oivc;
GLuint vertexShader = 0;
int success;
char infoLog[512];
if (vertexFile)
{
while (getline(vertexFile, inputVertexCode))
{
oivc << inputVertexCode << endl;
}
vertexCode_str = oivc.str();
const char* vertexCode = vertexCode_str.c_str();
vertexShader = glCreateShader(GL_VERTEX_SHADER); //Exception is thrown at this part
glShaderSource(vertexShader, 1, &vertexCode, 0);
glCompileShader(vertexShader);
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
if (!success)
{
glGetShaderInfoLog(vertexShader, 512, 0, infoLog);
MessageBoxA(0, infoLog, "ERROR-Failed to compile vertex shader !", MB_OK | MB_ICONSTOP);
}
}
else
{
MessageBoxA(0, "Failled to open vertex shader source code file!", "ERROR", MB_OK | MB_ICONSTOP);
}
fstream fragmentFile;
fragmentFile.open(fragment_file, ios::in);
string inputFragmentCode;
string fragmentCode_str;
ostringstream oifc;
GLuint fragmentShader = 0;
if (fragmentFile)
{
while (getline(fragmentFile, inputFragmentCode))
{
oifc << inputFragmentCode << endl;
}
fragmentCode_str = oifc.str();
const char* fragmentCode = fragmentCode_str.c_str();
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fragmentCode, 0);
glCompileShader(fragmentShader);
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
if (!success)
{
glGetShaderInfoLog(fragmentShader, 512, 0, infoLog);
MessageBoxA(0, infoLog, "ERROR-Failed to compile fragment shader", MB_OK | MB_ICONSTOP);
}
}
else
{
MessageBoxA(0, "Failled to open fragment shader source code file!", "ERROR", MB_OK | MB_ICONSTOP);
}
GLuint shaderProgram = 0;
shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
if (!success)
{
glGetProgramInfoLog(shaderProgram, 512, 0, infoLog);
MessageBoxA(0, infoLog, "ERROR-Failed to create shader program", MB_OK | MB_ICONSTOP);
}
return shaderProgram;
}
-
January 10th, 2018, 11:13 AM
#2
Re: Exception thrown at 0x00000000 when using DLL.
At which line does the issue occur?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
January 10th, 2018, 12:30 PM
#3
Re: Exception thrown at 0x00000000 when using DLL.
Code:
if (vertexFile)
{
while (getline(vertexFile, inputVertexCode))
{
oivc << inputVertexCode << endl;
}
vertexCode_str = oivc.str();
const char* vertexCode = vertexCode_str.c_str();
vertexShader = glCreateShader(GL_VERTEX_SHADER); //Exception is thrown at this part
glShaderSource(vertexShader, 1, &vertexCode, 0);
glCompileShader(vertexShader);
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
if (!success)
{
glGetShaderInfoLog(vertexShader, 512, 0, infoLog);
MessageBoxA(0, infoLog, "ERROR-Failed to compile vertex shader !", MB_OK | MB_ICONSTOP);
}
-
January 10th, 2018, 12:54 PM
#4
Re: Exception thrown at 0x00000000 when using DLL.
What is the type of DLL you created?
Did you try to debug the DLL code?
Victor Nijegorodov
-
January 10th, 2018, 01:01 PM
#5
Re: Exception thrown at 0x00000000 when using DLL.
-
January 10th, 2018, 01:51 PM
#6
Re: Exception thrown at 0x00000000 when using DLL.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
January 10th, 2018, 03:00 PM
#7
Re: Exception thrown at 0x00000000 when using DLL.
Originally Posted by 2kaud
Thank you so much 2kaud your help gave me hint I need to do some opengl initialization procedure for the DLL and now it's work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|