Re: [XFree86] XShmSegmentInfo issues
that's the conclusion i came to late last night too. now, for each of my XImage helper class instances, i declare a XShmSegmentInfo* in the ctor and point it to a new'd buffer so it hangs until the class dtor gets rid of it as my app is ending. seems to work okay for now. Looking through the code, it looks like Xlib stores a pointer to the shminfo. I didn't realize it did that. That would imply that each XImage needs a XShmSegmentInfo that sticks around for the life of the XImage. It impresses me that it is a mistake that it did this rather than copying the contents of the XShmSegmentInfo. I'm not sure why it was implemented that way. I don't think we have any XShm man pages. If we did, hopefully, they would mention something like that. The error must be that the first XImage ends up with the second XImage's data and subsequently the operation appears to be addressing outside of the shared memory segment, so the BadValue error happens. ___ XFree86 mailing list [EMAIL PROTECTED] http://XFree86.Org/mailman/listinfo/xfree86
[XFree86] XShmSegmentInfo issues
i have a methods in a class to create a shared memory x image - it creates and stores an xImage in the usual way: XShmSegmentInfo shminfo; ximage = XShmCreateImage(..., shminfo); shminfo.shmid = shmget (.., ximage-height * ximage-bytes_per_line, ...); shminfo.shmaddr = ximage-data = shmat(shminfo.shmid, 0, 0); shminfo.readOnly = False; XShmAttach (display, shminfo); i call this method in several places and only call XShmPutImage on the xImage later in my code. i get an X error: X Error of failed request: BadValue (integer parameter out of range for operation) Major opcode of failed request: 144 (MIT-SHM) Minor opcode of failed request: 3 (X_ShmPutImage) which appears to be because the shared segment info has changed. if i save the shminfo each time and then re-attach it to the display before i call XShmPutImage, i still get the problem. any ideas ? what is the right thing to do here. also - in the code i'm using there is a call to: shmctl ( shmInfo.shmid, IPC_RMID, NULL ); just after it's created - surely this is wrong and i shouldn't remeove the sgm segment until my program is finishing. thanks in advance as always. ___ XFree86 mailing list [EMAIL PROTECTED] http://XFree86.Org/mailman/listinfo/xfree86
Re: [XFree86] XShmSegmentInfo issues
I think you've misinterpreted this. Aside from corruption of the ximage data structure, the only time BadValue is returned is if your source rectangle passed to XShmPutImage lies outside of the XImage (or if you pass junk for the send_event). Check your dimensions passed to XShmPutImage. that's odd then - if a rearrange my code so i call create 1 then write 1 then create 2 then write 2 it works perfectly. if i call create 1 create 2 write 1 write 2 it fails with the X error i mentioned. (where 'create' does all the shm stuff and creation of the ximage and 'write' does the 'XShmPutImage' so i don't need to save/restone any of the XShmSegmentInfo then ? Segments don't disappear until after they are removed and the last process attaching to them has detached. Even if you remove it, it will not go away until after you detach. When your program quits or crashes, it detaches automatically. However, it does not get removed automatically, so if the app quits or crashes before removing the segment, the segment will get leaked. That's why it's common practice to attach and then remove a segment. thanks for that clarification - excellent. ___ XFree86 mailing list [EMAIL PROTECTED] http://XFree86.Org/mailman/listinfo/xfree86
Re: [XFree86] BadAccess errors using XShmPutImage
Many thanks Mark - that was exactly the problem - works perfectly now. It's likely that you're not handling the padding correctly. Is (ximage-bytes_per_line == windowWidth * windowDepthBytes) ? In general, I like to create the XImage first and then allocate the data later. That saves you from having to do the work of finding out what the padding is supposed to be. That is, pass NULL for the data field in XShmCreateImage. Then shmget with (ximage-height * ximage-bytes_per_line), then fill in ximage-data with the value returned by shmat. Eg: ximage = XShmCreateImage(..., shminfo); shminfo.shmid = shmget (.., ximage-height * ximage-bytes_per_line, ...); shminfo.shmaddr = ximage-data = shmat(shminfo.shmid, 0, 0); shminfo.readOnly = False; XShmAttach (display, shminfo); So the pitch you should use is ximage-bytes_per_line. You can get that independently by looking up pixmap formats, but it's easier to just have XShmCreateImage fill it in for you. Mark. On Mon, 3 Nov 2003, Callum Prentice wrote: 1) Does your X-server have SHM support? MIT-SHM should show up in the list of extensions reported by xdpyinfo. Yep - that extension is listed when i run xdpyinfo. 2) Does your operating system have SHM support? This sort of thing is often disabled for security reasons. i'm not sure how to test this - i'm very much a x/unix novice - but after adding printf's to another library i've been looking at (SDL), it seems that it is - SDL is certainly calling XShmPutImage () successfully. 3) Programming errors on your part? BadAccess is generated if: Very likely. a) the server doesn't know about the segment (you called XShmAttach on it didn't you?). Yep - I do that. b) The size is bad, that is, the segment is too small to contain the source you specified (or the XImage is improperly initialized). I suspect that it is some kind of unitialized structure problem. I chopped the return value tests and the error handler out of my code for clarity and tacked it on the end of this message - might be something obvious. Thanks. cp snip shmInfo.shmid = shmget ( IPC_PRIVATE, windowWidth * windowDepthBytes * windowHeight, IPC_CREAT | 0777 ); shmInfo.shmaddr = (char *)shmat ( shmInfo.shmid, 0, 0); shminfo.readOnly = False; XShmAttach ( display, shmInfo ); XSync ( display, True ); shmctl ( shmInfo.shmid, IPC_RMID, NULL ); pixels = shmInfo.shmaddr; ximage = XShmCreateImage ( display, DefaultVisual ( display, screen ), windowDepth, ZPixmap, shmInfo.shmaddr, shmInfo, windowWidth, windowHeight ); XShmPutImage ( display, window, DefaultGC ( display, screen ), ximage, 0, 0, 0, 0, windowWidth, windowHeight, False ); -- i'm attempting to put together a simple test that creates a window, allocates a buffer in memory and using an XImage and XShmPutImage () displays it on my screen. i have a tiny piece of code that (as far as i know) does all the right things - it creates the window but when i try to display the contents of my buffer via an XImage i get a message like this: X Error of failed request: BadAccess (attempt to access private resource denied) Major opcode of failed request: 144 (MIT-SHM) Minor opcode of failed request: 3 (X_ShmPutImage) i've seen this type of problem described in the newsgroups but there don't seem to be any answers posted. i check the return from all my previous calls and they're fine. i'm using XFree86 version 4.3.0 (27 feb 2003), X Protocol version 11, rev 0, rel 6.6 and my OS is NetBSD/i386 1.6 [elf]. ___ XFree86 mailing list [EMAIL PROTECTED] http://XFree86.Org/mailman/listinfo/xfree86
[XFree86] BadAccess errors using XShmPutImage
i'm attempting to put together a simple test that creates a window, allocates a buffer in memory and using an XImage and XShmPutImage () displays it on my screen. i have a tiny piece of code that (as far as i know) does all the right things - it creates the window but when i try to display the contents of my buffer via an XImage i get a message like this: X Error of failed request: BadAccess (attempt to access private resource denied) Major opcode of failed request: 144 (MIT-SHM) Minor opcode of failed request: 3 (X_ShmPutImage) i've seen this type of problem described in the newsgroups but there don't seem to be any answers posted. i check the return from all my previous calls and they're fine. i'm using XFree86 version 4.3.0 (27 feb 2003), X Protocol version 11, rev 0, rel 6.6 and my OS is NetBSD/i386 1.6 [elf]. can anyone shed any light on this please? thanks. cp ___ XFree86 mailing list [EMAIL PROTECTED] http://XFree86.Org/mailman/listinfo/xfree86
[XFree86] BadAccess errors using XShmPutImage
i'm attempting to put together a simple test that creates a window, allocates a buffer in memory and using an XImage and XShmPutImage () displays it on my screen. i have a tiny piece of code that (as far as i know) does all the right things - it creates the window but when i try to display the contents of my buffer via an XImage i get a message like this: X Error of failed request: BadAccess (attempt to access private resource denied) Major opcode of failed request: 144 (MIT-SHM) Minor opcode of failed request: 3 (X_ShmPutImage) i've seen this type of problem described in the newsgroups but there don't seem to be any answers posted. i check the return from all my previous calls and they're fine. i'm using XFree86 version 4.3.0 (27 feb 2003), X Protocol version 11, rev 0, rel 6.6 and my OS is NetBSD/i386 1.6 [elf]. can anyone shed any light on this please? thanks. cp ___ XFree86 mailing list [EMAIL PROTECTED] http://XFree86.Org/mailman/listinfo/xfree86
Re: [XFree86] BadAccess errors using XShmPutImage
1) Does your X-server have SHM support? MIT-SHM should show up in the list of extensions reported by xdpyinfo. Yep - that extension is listed when i run xdpyinfo. 2) Does your operating system have SHM support? This sort of thing is often disabled for security reasons. i'm not sure how to test this - i'm very much a x/unix novice - but after adding printf's to another library i've been looking at (SDL), it seems that it is - SDL is certainly calling XShmPutImage () successfully. 3) Programming errors on your part? BadAccess is generated if: Very likely. a) the server doesn't know about the segment (you called XShmAttach on it didn't you?). Yep - I do that. b) The size is bad, that is, the segment is too small to contain the source you specified (or the XImage is improperly initialized). I suspect that it is some kind of unitialized structure problem. I chopped the return value tests and the error handler out of my code for clarity and tacked it on the end of this message - might be something obvious. Thanks. cp snip shmInfo.shmid = shmget ( IPC_PRIVATE, windowWidth * windowDepthBytes * windowHeight, IPC_CREAT | 0777 ); shmInfo.shmaddr = (char *)shmat ( shmInfo.shmid, 0, 0); shminfo.readOnly = False; XShmAttach ( display, shmInfo ); XSync ( display, True ); shmctl ( shmInfo.shmid, IPC_RMID, NULL ); pixels = shmInfo.shmaddr; ximage = XShmCreateImage ( display, DefaultVisual ( display, screen ), windowDepth, ZPixmap, shmInfo.shmaddr, shmInfo, windowWidth, windowHeight ); XShmPutImage ( display, window, DefaultGC ( display, screen ), ximage, 0, 0, 0, 0, windowWidth, windowHeight, False ); -- i'm attempting to put together a simple test that creates a window, allocates a buffer in memory and using an XImage and XShmPutImage () displays it on my screen. i have a tiny piece of code that (as far as i know) does all the right things - it creates the window but when i try to display the contents of my buffer via an XImage i get a message like this: X Error of failed request: BadAccess (attempt to access private resource denied) Major opcode of failed request: 144 (MIT-SHM) Minor opcode of failed request: 3 (X_ShmPutImage) i've seen this type of problem described in the newsgroups but there don't seem to be any answers posted. i check the return from all my previous calls and they're fine. i'm using XFree86 version 4.3.0 (27 feb 2003), X Protocol version 11, rev 0, rel 6.6 and my OS is NetBSD/i386 1.6 [elf]. ___ XFree86 mailing list [EMAIL PROTECTED] http://XFree86.Org/mailman/listinfo/xfree86