Access violation error when using Hazel

I was following a youtube video on using Hazel https://www.youtube.com/watch?v=zn7N7zHgCcs and I have everyday installed quite OK. However I encounter an exception in Hazelnut.exe "Access violation executing location 0x0000000 on Hazel::OpenGLShader::CreateProgram.

If anyone is familiar with Hazel and has looked at "The Cherno" youtube videos and can help, that would be greatly appreciated.
Is Hazelnut.exe a program you've compiled yourself, or an exe you've been provided?
The source code for that CreateProgram function seems to be at https://github.com/TheCherno/Hazel/blob/master/Hazel/src/Platform/OpenGL/OpenGLShader.cpp so if you can debug that function, you might be able to tell where the access violation happens.

Might help if you can narrow down what time in that 30-minute-long video is actually relevant to your problem.
I'm unfamiliar with "Hazel" and "The Cherno". I can only offer an educated guess without access to your code and information about your computer.

From names alone I assume that your program explicitly links symbols at runtime during some initialization process. I suspect that this initialization process fails, is defective, doesn't happen, or doesn't happen early enough.

Use a debugger to figure out which symbol(s) are problematic. The problematic symbol(s) are most likely functions that are expected to be explicitly linked, for example glCreateProgram.
@Ganado, Yes, I have the entire code from github and the exe is generated after running the solution file. The exception occurs at line 319 of the OpenGLShader.cpp file, but I don't understand that code enough yet to debug it. So I am actually looking for help from someone who understands that code. I just need to use Hazel to achieve other things I need but I am not conversant with it.
Last edited on
Sounds like the issue is what mbozzi said, then.

You're going to need to change some code and do some troubleshooting.
See this Stack Overflow thread: https://stackoverflow.com/questions/12329082/glcreateshader-is-crashing
(not the exact same error, but it sounds very close)

The GUI being used is GLFW, but I see no calls like glfwInit() anywhere. (Edit: Actually I do see the call, GitHub's search functionality is just garbage.)
Is like 50 in https://github.com/TheCherno/Hazel/blob/master/Hazel/src/Platform/Windows/WindowsWindow.cpp being hit?
The underlying problem may be that GLEW, which GLFW apparently uses, in order to link correct OpenGL calls, isn't being initialized.

serg06 wrote:
If it's a problem with GLFW, you can ask them for an error message before they crash your program.

Windows example:

Create a callback function:

1
2
3
4
5
6
#include <windows.h>
void glfw_onError(int error, const char* description)
{
    // print message in Windows popup dialog box
    MessageBox(NULL, description, "GLFW error", MB_OK);
}


and set it at the very beginning of your code.

glfwSetErrorCallback(glfw_onError);
Last edited on
Sorry please bear with me, not yet conversant with lots of things. Should the code above be placed at the beginning of which file ? WindowsWindow.cpp? The arguments description and "GLFW error" seem not to match. It says argument of type char* is not compatible with parameter of type LPCWSTR. How do I initialize GLEW?
Last edited on
LPCWSTR is MS speak for pointer to type const wchar_t (which is 16 bit and used by MS for unicode chars instead of char).

Are you compiling as unicode or multi-byte character set?

If compiling as unicode then you use wchar_t instead of char. If you don't need to compile as unicode, then try changing the compile character set to multi-byte.
OK. what about the string there "GFLW error". It still is expecting a LPCWSTR. Also inside which file do I place this callback function?
If you're using wide strings, you do L"GLFW Error" instead of just "GLFW Error".

I'd call it from somewhere in WindowsWindow::Init(const WindowProps& props) where you see the other calls to SetXYZCallback.
Last edited on
Thanks for directing me aright with the L"GLFW Error". Actually I was trying to define and set that function at the location you just mentioned, but I observed that glfwSetErrorCallback() wont take as input argument a function that returns void; such as void glfw_onError(). I will try to redefine the function to return GLFWerrorfun and let you know.
Hmm, post the compiler error message you get. GLFWerrorfun is a function pointer type so doubt that should be the return type of the callback function passed into glfwSetErrorCallback.

Because according to the documentation, GLFWerrorfun is defined as:
typedef void(* GLFWerrorfun) (int error_code, const char *description)
Meaning it's a pointer to a function that returns void, and expects (int, const char*) as parameters.

The problem may be that the 'description' being passed to MessageBox is not a wide string. So you may have to convert the description into a wide string.

Or, instead of calling MessageBox, explicitly use the ASCII version, MessageBoxA and remove the L from L"GLFW Error".
Last edited on
OK, so I changed MessageBox to MessageBoxA and I did not need to have wchar_t and L prepended to "GFLW error". And the signatures/types matched to have gflw_onerror as input to glfwSetErrorCallback. However I don't find any message box popup when i run it and I still have the Access violation error.

Below is the top part of the code I have within Hazel namespace of WindowsWindow.cpp:


static void glfw_onError(int error, const char* description)
{
// print message in Windows popup dialog box
MessageBoxA(NULL, description, "GLFW error", MB_OK);

}

static void GLFWErrorCallback(int error, const char* description)
{
HZ_CORE_ERROR("GLFW Error ({0}): {1}", error, description);
}

WindowsWindow::WindowsWindow(const WindowProps& props)
{
HZ_PROFILE_FUNCTION();

Init(props);
}

WindowsWindow::~WindowsWindow()
{
HZ_PROFILE_FUNCTION();

Shutdown();
}

void WindowsWindow::Init(const WindowProps& props)
{
HZ_PROFILE_FUNCTION();

m_Data.Title = props.Title;
m_Data.Width = props.Width;
m_Data.Height = props.Height;

HZ_CORE_INFO("Creating window {0} ({1}, {2})", props.Title, props.Width, props.Height);
glfwSetErrorCallback(glfw_onError);
if (s_GLFWWindowCount == 0)
{
HZ_PROFILE_SCOPE("glfwInit");
int success = glfwInit();

HZ_CORE_ASSERT(success, "Could not initialize GLFW!");

glfwSetErrorCallback(GLFWErrorCallback);
}
Update: @Ganado, I just managed to isolate the problem code section! Within the function definition void OpenGLShader::CreateProgram() I removed everything that had to do with shaders and the exe ran at least reasonably ok enough for me to proceed with the things I need to learn. Thank you so much for supporting me through this. Greatly appreciated!.
Topic archived. No new replies allowed.