floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
6.55k stars 469 forks source link

sokol_gfx: Validation error when creating offscreen pass. #949

Closed comblock closed 7 months ago

comblock commented 7 months ago

I have a basic project set up with a triangle rendering and cimgui, but when I try to add an offscreen pass with the following code:

        .offscreen = {
            .color = sg_make_image(&(sg_image_desc) {
                .render_target = true,
                .width = 92,
                .height = 52,
                .pixel_format = SG_PIXELFORMAT_RGBA8,
            }),
            .pass = sg_make_pass(&(sg_pass_desc) {
                .color_attachments[0].image = state.offscreen.color,
                .label = "Offscreen pass"
            }),
            .pass_action = (sg_pass_action) {
                .colors[0] = {.load_action = SG_LOADACTION_CLEAR, .clear_value = {0.0, 0.0, 0.0, 1.0}},
            }
        }

I get this validation error:

[sg][error][id:165] libs/sokol/sokol_gfx.h:16063:0: 
        VALIDATE_PASSDESC_NO_ATTACHMENTS: sg_pass_desc no color or depth-stencil attachments

[sg][panic][id:258] libs/sokol/sokol_gfx.h:15603:0: 
        VALIDATION_FAILED: validation layer checks failed

even though I did set a color attachment. My guess is that I did something wrong but the example code in the docs is pretty much the same.

floooh commented 7 months ago

My guess would be that state.offscreen.color isn't initialized yet at the time when sg_make_pass() is called. Just a shot in the dark though. I would check that by stepping through the code with a debugger (the code snippet alone isn't enough to confirm, it would be important to know what the surrounding code looks like, but I wouldn't assume that values in a designated initialization block are assigned before the end of entire statement).

comblock commented 7 months ago

My guess would be that state.offscreen.color isn't initialized yet at the time when sg_make_pass() is called.

I thought I had checked this wasn't the issue, but it was ¯\(ツ)/¯. Thank you!