floooh / sokol

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

[sokol_app]: opengl context creation fails when attempting to create or attach to existing console #805

Closed EnokViking closed 1 year ago

EnokViking commented 1 year ago

passing win32_console_attach OR create = true to sapp_run via sapp_desc when requesting an opengl context results in an erroneous state where context creation fails with the error: "WIN32_WGL_OPENGL_3_2_NOT_SUPPORTED: OpenGL 3.2 not supported by GL driver (ERROR_INVALID_VERSION_ARB) ./SokolApp.h, at line: 6642".

floooh commented 1 year ago

Oh, that is both weird and unexpected because those two things should be entirely unrelated to each other. I'll need to try and reproduce on my Windows machines.

Can you share a bit more information about your setup? At least Windows version and GPU vendor?

floooh commented 1 year ago

Hmm, I can't seem to reproduce the problem here (my config: Win10 Home 22H2, NVIDIA RTX 2070 driver version 528.24).

I used the clear-sapp sample, and added the following to the init() function:

    switch (sg_query_backend()) {
        case SG_BACKEND_D3D11: printf("Hello from D3D11\n"); break;
        case SG_BACKEND_GLCORE33: printf("Hello from GL\n"); break;
        case SG_BACKEND_METAL_MACOS: printf("Hello from Metal\n"); break;
        default: printf("???\n");
    }

...and changed sokol_main like this:

sapp_desc sokol_main(int argc, char* argv[]) {
    (void)argc;
    (void)argv;
    return (sapp_desc){
        //...
        .win32_console_create = true,
        .win32_console_utf8 = true,
    };
}

Do you have some more information for me which would help me identifying the problem?

PS: screenshot image

floooh commented 1 year ago

PPS: same result on my laptop which has the same Win10 build, but an integrated Intel HD Graphics 520 GPU.

EnokViking commented 1 year ago

I was reluctant to post this issue since I'm binding from another language(beef) and figured I was just doing something wrong on my end which turned out to be the case so you can sleep well tonight. There was a size mismatch of 8 bytes between the sapp_desc i was passing into sapp_run and the expected data. I stepped into sapp_run and verified that like so: weird

The culprit ended up being sapp_logger, I had simply forgotten to add the userdata member and that didn't occur to me since I was just copy-pasting the structs and changing the types.. >> Sorry for having you verify this, but thanks for the sanity check.

floooh commented 1 year ago

Hmm, reminds me that there's this language bindings generator PR which I still haven't looked into yet (which needs a bit of work though):

https://github.com/floooh/sokol/pull/496