assembly 尝试关闭X11中的显示器时出现BadWindow(无效窗口参数)

nx7onnlm  于 2023-01-26  发布在  其他
关注(0)|答案(1)|浏览(268)

我在x86 - 64 NASM汇编中编写,我编写了一个函数,通过WSL在Ubuntu上使用X11关闭窗口
我一直收到这个错误:

X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  18 (X_ChangeProperty)
  Resource id in failed request:  0xe002a0
  Serial number of failed request:  8
  Current serial number in output stream:  18

我的代码看起来像这样:

section .bss
    Ox:     resd 1
    Oy:     resd 1
    null:   resq 1
    dis:    resq 1             ;pointer to dis
    screen: resq 1
    gc:     resq 1

    black:  resq 1
    white:  resq 1
    red:    resq 1
    blue:   resq 1
    win:    resq 21
    event:  resb 0x60

    
section .text
extern  printf, exit
extern  XOpenDisplay, XCreateSimpleWindow, XSetStandardProperties, XSelectInput, XCreateGC, XSetBackground, XSetForeground, XClearWindow, XMapRaised, XFreeGC, XDestroyWindow, XCloseDisplay, XNextEvent

global main
main:
    push    rbp
    mov     rbp, rsp

    call    init

    call    closeWin

    mov     rsp, rbp
    pop     rbp
    ret

init:
    push    rbp
    mov     rbp, rsp

    mov     dword [Ox], 100
    mov     dword [Oy], 100
    mov     qword [black], 0x000000
    mov     qword [white], 0xffffff
    mov     qword [red], 0xff0000
    mov     qword [blue], 0x0000ff

    lea     rdi, 0
    call    XOpenDisplay
    mov     qword [dis], rax

    mov     rax, [dis+0xe0]
    mov     qword [screen], rax

    mov     rax, [dis]
    mov     rdx, [rax +0xe8]
    mov     rax, [dis]
    mov     eax, [rax + 0xe0]
    cdqe
    shl     rax, 7
    add     rax, rdx
    mov     rax, [rax + 0x10]
    
    mov     rdi, [dis]
    mov     rsi, rax
    mov     rdx, 0
    mov     rcx, 0
    mov     r8, 300
    mov     r9, 300

    mov     rax, [black]
    push    rax
    mov     rax, [white]
    push    rax
    mov     rax, 5
    push    rax
    call    XCreateSimpleWindow
    mov     [win], rax    
    add     rsp, 24


    mov     rdi, [dis]
    mov     rsi, [dis]
    mov     rax, "Title"
    push    rax
    mov     rax, "Hi"
    push    rax
    lea     rdx, [rbp-8]
    lea     rcx, [rbp-16]
    mov     r8, 0
    mov     r9, 0x0
    push    r8
    push    r9
    call    XSetStandardProperties
    add     rsp, 0x20

    mov     rdi, [dis]
    mov     rsi, [win]
    mov     rdx, ExposureMask
    mov     rax, ButtonPressMask
    or      rdx, rax
    mov     rax, KeyPressMask
    or      rdx, rax
    call    XSelectInput

    mov     rdi, [dis]
    mov     rsi, [win]
    xor     rdx, rdx
    xor     rcx, rcx
    call    XCreateGC
    mov     [gc], rax

    mov     rdi, [dis]
    mov     rsi, [gc]
    mov     rdx, [white]
    call    XSetBackground

    mov     rdi, [dis]
    mov     rsi, [gc]
    mov     rdx, [black]
    call    XSetForeground

    mov     rdi, [dis]
    mov     rsi, [win]
    call    XClearWindow

    mov     rdi, [dis]
    mov     rsi, [win]
    call    XMapRaised

    mov     rsp, rbp
    pop     rbp
    ret

closeWin:
    push    rbp
    mov     rbp, rsp

    mov     rdi, [dis]
    mov     rsi, [gc]
    call    XFreeGC

    mov     rdi, [dis]
    mov     rsi, [win]
    call    XDestroyWindow

    mov     rdi, [dis]
    call    XCloseDisplay

    xor     rdi, rdi
    call    exit

    mov     rsp, rbp
    pop     rbp
    ret

错误似乎来自XCloseDisplay函数调用
我试着查看窗口的初始化,但是当我注解掉call XCloseDisplay时,我没有得到任何错误。
我试着只是注解出来并忽略它,但在尝试使用XNextEvent时得到了同样的错误
(also我在组装时有点noob,所以这可能是我忽略的一件愚蠢的事情)

gt0wga4j

gt0wga4j1#

没关系,我只是在初始化时将显示传递到XSetStandardProperties的窗口参数中,但我只是在试图关闭显示时才得到错误。

相关问题