Having issues with XPutImage

2019-09-12 01:02发布

I have these function calls :

OSPImgBlit(&img->_obj, &win1->_obj, 0, 0, 0, 0, 640, 480);
OSPRun(&win1->_obj, OSPWND_SWAP);

for these implementations :

void OSPwnd_swap(OSPobj *obj, va_list arg) {
    OSPwindow *wnd = (OSPwindow *) obj;
    XdbeSwapInfo swpifo;

    swpifo.swap_window = wnd->_wnd;
    swpifo.swap_action = XdbeUndefined;

    // XdbeSwapBuffers returns true on success, we return 0 on success.
    if(XdbeSwapBuffers(wnd->_dpy->_dpy, &swpifo, 1)) {
        OSPrint(1, "OSPwnd_swap : Window %d swapped "
                    "on connection %d",
                    wnd->_wnd, XConnectionNumber(wnd->_dpy->_dpy));
/*      XFlush(wnd->_dpy->_dpy); */
    }
    else {
        OSPrint(1, "OSPwnd_swap : Unable to swap window %d "
                    "on connection %d",
                    wnd->_wnd, XConnectionNumber(wnd->_dpy->_dpy));
    }
}

void OSPImgBlit(OSPobj *orig, OSPobj *dest, int x_orig, int y_orig,
            int x_dest, int y_dest, unsigned int width, unsigned int height) {
    OSPimage *orig_as_image = (OSPimage *) orig;
    OSPwindow *orig_as_window = (OSPwindow *) orig;
    OSPimage *dest_as_image = (OSPimage *) dest;
    OSPwindow *dest_as_window = (OSPwindow *) dest;

    enum {
        image_to_image = 0,
        image_to_window = 1,
        window_to_image = 2,
        window_to_window = 3
    } mode = image_to_window;

    switch(mode) {
        case image_to_window:
            XPutImage(dest_as_window->_dpy->_dpy, dest_as_window->_bbf,
                        dest_as_window->_gc, orig_as_image->_img,
                        x_orig, y_orig, x_dest, y_dest, width, height);
        default:;
    }
}

The entire code is here : https://github.com/DJTECKING/OSPOOC.git

My application starts correctly but when I attempt to close the window I created, it happen one of these behavior randomly : - segfault - BadDrawable on X_PutImage - nothing (not working close button on closing window) - Correctly closed window and application

I guess something like I'm using a already closed window or freed image, but in the entire code I don't understand how can this happen, any idea?

Also XPutImage only blits a square while I was attempting to copy the whole window.

Yet another question that might be separated of this topic, I continue to face ugly tearing effects, even with Xdouble buffer extension, was not this extension supposed to avoid this?

I haven't 10 reputation so here is direct image link: http://i.stack.imgur.com/AnlMo.png

标签: c image git x11
1条回答
闹够了就滚
2楼-- · 2019-09-12 01:35

Tearing effects might due to Xdbe mate implementation No tearing effects under waylang on fedora22.

Segfault and BadDrawable is due to the event processing loop in OSPwnd:OSPDpyHdl. It wasn't stopping till the event queue was empty, events on closing window arrived before other one like mouse pointer entering window. Then OSPDpyHdl was deleting objects before using them to retrieve next events. These events were also not treated corectly before returning from OSPDpyHdl.

Partial XPutImage was due to the fact that user can't access data table of an image by the [x][y] order since image is line contigous in memory. So win->_data[y] accesses to each line and win->_data[y][x] each pixel.

The problem is that all image is sent 60 times per second encumbering the X connection and disabling server reactivity.

查看更多
登录 后发表回答