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

not work on macOS Catalina 10.15.6 #12

Open
MarcoQin opened this issue Aug 5, 2020 · 4 comments
Open

not work on macOS Catalina 10.15.6 #12

MarcoQin opened this issue Aug 5, 2020 · 4 comments

Comments

@MarcoQin
Copy link

MarcoQin commented Aug 5, 2020

Build command: gcc -std=c99 -O2 -Wall -Wextra -Wpedantic main.c -I/usr/X11R6/include -L/usr/X11R6/lib -lSDL2 -lX11 -o paperview

Run command: ./paperview cyber 5

Output:

2020-08-05 16:56:07.067 paperview[39543:6127143] -[__NSTaggedDate title]: unrecognized selector sent to instance 0x1d1
2020-08-05 16:56:07.067 paperview[39543:6127143] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSTaggedDate title]: unrecognized selector sent to instance 0x1d1'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff36cfcb57 __exceptionPreprocess + 250
	1   libobjc.A.dylib                     0x00007fff6f9aa5bf objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff36d7bbe7 -[NSObject(NSObject) __retain_OA] + 0
	3   CoreFoundation                      0x00007fff36c613bb ___forwarding___ + 1427
	4   CoreFoundation                      0x00007fff36c60d98 _CF_forwarding_prep_0 + 120
	5   libSDL2-2.0.0.dylib                 0x0000000101047b5c Cocoa_CreateWindowFrom + 44
	6   libSDL2-2.0.0.dylib                 0x000000010101f160 SDL_CreateWindowFrom_REAL + 186
	7   paperview                           0x0000000100f998f3 main + 115
	8   libdyld.dylib                       0x00007fff70b52cc9 start + 1
	9   ???                                 0x0000000000000003 0x0 + 3
)
libc++abi.dylib: terminating with uncaught exception of type NSException
@glouw
Copy link
Owner

glouw commented Aug 6, 2020

Does this example work for you?
https://stackoverflow.com/questions/34425799/use-root-x11-window-as-the-main-sdl2-window

It should just paint the screen one solid color.

@MarcoQin
Copy link
Author

MarcoQin commented Aug 6, 2020

No, it's not work, too. And the example result in the same error.

But X11 window is runnable, following snippet is working:

#include <X11/Xlib.h> // Every Xlib program must include this
#include <assert.h>   // I include this to test return values the lazy way
#include <unistd.h>   // So we got the profile for 10 seconds

#define NIL (0)       // A name for the void pointer

main()
{
      Display *dpy = XOpenDisplay(NIL);
      assert(dpy);
      Window w = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0,
			       200, 100, 0,
			       CopyFromParent, CopyFromParent, CopyFromParent,
			       NIL, 0);
      XMapWindow(dpy, w);
      XFlush(dpy);
      sleep(10);
}

Snipet that not work:

#include <SDL2/SDL.h>

#include <X11/Xlib.h>

#include <stdio.h>

// clang -lSDL2 -lX11 -I/usr/include/SDL2 -Weverything x11.c -o x11

int main(void)
{
    Display *x11_d;
    int x11_s;
    Window x11_w;
    SDL_Window *w;
    SDL_Renderer *r;

    x11_d = XOpenDisplay(NULL);

    if(!x11_d) {
        fprintf(stderr, "couldn't open display\n");
        return 1;
    }

    /* x11_s = DefaultScreen(x11_d); */
    /* x11_w = RootWindow(x11_d, x11_s); */

    x11_w = XCreateWindow(x11_d, DefaultRootWindow(x11_d), 0, 0,
            200, 100, 0,
            CopyFromParent, CopyFromParent, CopyFromParent,
            0, 0);
    XMapWindow(x11_d, x11_w);

    if(SDL_Init(SDL_INIT_VIDEO) != 0) {
        fprintf(stderr, "couldn't initialize SDL: %s\n", SDL_GetError());
        return 1;
    }

    w = SDL_CreateWindowFrom((void *)x11_w);

    /* XCloseDisplay(x11_d); */

    if(!w) {
        fprintf(stderr, "couldn't attach to the root X11 window: %s\n", SDL_GetError());
        return 1;
    }
    printf("here haha\n");

    r = SDL_CreateRenderer(w, -1, 0);

    SDL_SetRenderDrawColor(r, 255, 0, 0, 255);
    SDL_RenderClear(r);
    SDL_RenderPresent(r);

    SDL_Delay(5700);

    SDL_Quit();
    return 0;
}

@glouw
Copy link
Owner

glouw commented Aug 6, 2020

This looks to be a similar error:

https://stackoverflow.com/questions/30185781/sdl-createwindowfrom-with-qt-widget-under-mac-os

Maybe the problem lies with how the window is being created. Since this is OSX specific I am not of much help

@MarcoQin
Copy link
Author

MarcoQin commented Aug 7, 2020

Anyway, thank you! I will try again when I have time.

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

2 participants