Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGSEGV when calling any function #78

Closed
mondegreengames opened this issue Jun 3, 2023 · 1 comment
Closed

SIGSEGV when calling any function #78

mondegreengames opened this issue Jun 3, 2023 · 1 comment

Comments

@mondegreengames
Copy link
Contributor

This is my first time using zgl, and I'm still super new at Zig. But I tried running this super simple example:

const std = @import("std");
const c = @cImport({
    @cInclude("SDL.h");
});
const gl = @import("third-party/zgl/zgl.zig");

pub fn main() !void {

     _ = c.SDL_Init(c.SDL_INIT_VIDEO);
    defer c.SDL_Quit();

    var window = c.SDL_CreateWindow("Hello, world!", c.SDL_WINDOWPOS_CENTERED, c.SDL_WINDOWPOS_CENTERED, 640, 400, c.SDL_WINDOW_OPENGL);
    defer c.SDL_DestroyWindow(window);

    var glContext = c.SDL_GL_CreateContext(window);
    defer c.SDL_GL_DeleteContext(glContext);

    mainloop: while (true) {
        var sdl_event: c.SDL_Event = undefined;
        while (c.SDL_PollEvent(&sdl_event) != 0) {
            switch (sdl_event.type) {
                c.SDL_QUIT => break :mainloop,
                else => {},
            }
        }

        // this line will crash!
        // Output: Stop reason: signal SIGSEGV: invalid address (fault address: 0x0)
        gl.clear(.{.color = true, .depth = true });

        c.SDL_GL_SwapWindow(window);
    }
}

As soon as it executes the gl.clear() line I get Stop reason: signal SIGSEGV: invalid address (fault address: 0x0)

Valgrind reports this:

==121080== Jump to the invalid address stated on the next line
==121080==    at 0x0: ???
==121080==    by 0x20C3D4: main.main (main.zig:30)
==121080==    by 0x20C946: callMain (start.zig:609)
==121080==    by 0x20C946: initEventLoopAndCallMain (start.zig:543)
==121080==    by 0x20C946: callMainWithArgs (start.zig:493)
==121080==    by 0x20C946: main (start.zig:508)
==121080==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==121080== 

It seems like gl.Clear() itself (and any other functions I've tried) is somehow null, which seems weird because from looking at the zgl source it's a regular function, not a dynamically loaded function pointer or anything like that.

If I were using GLEW I would assume I didn't call glewInit(), but I haven't seen a similar zgl function in any of the examples I've found.

Am I missing something simple?

@mondegreengames
Copy link
Contributor Author

I was missing something:

gl.loadExtensions({}, myWrapperAroundSDL_GL_GetProcAddress);

I'm not sure why none of the examples I found had that line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant