Events suddenly triggered while using wxAlphaPixelData

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Events suddenly triggered while using wxAlphaPixelData

Andreas Falkenhahn
Strange things are going on here. I use this code to write raw pixels from a memory buffer to a wxBitmap:

=================================================================

        wxAlphaPixelData pixData(*dstbm, wxPoint(data->DstX, data->DstY), wxSize(data->Width, data->Height));    
        if(!pixData) return;
               
        wxAlphaPixelData::Iterator p(pixData);
               
        printf("in\n");
                       
        for(int y = 0; y < data->Height; y++) {
                       
                int bitmask = 1<<(~data->SrcX&7);
                       
                src += data->SrcX * 4;
                                                       
                wxAlphaPixelData::Iterator rowStart = p;
                                                       
                for(int x = 0; x < data->Width; x++) {
                 
                        int enter = 1;
                               
                        if(mask) enter = (mask[(data->SrcX + x)>>3] & bitmask);
                               
                        if(enter) {  
                                       
                                if(premultiply) {
                                               
                                        UBYTE av = src[a];
                                               
                                        p.Red()   = dopremultiply(src[r], av);
                                        p.Green() = dopremultiply(src[g], av);
                                        p.Blue()  = dopremultiply(src[b], av);
                                                                                               
                                } else {                                        
                                                                                                               
                                        p.Red()   = src[r];
                                        p.Green() = src[g];
                                        p.Blue()  = src[b];
                                }
                                       
                                p.Alpha() = (doalpha) ? src[a] : 255;
                                src += 4;    
                                                               
                        } else {
                                                                               
                                src += 4;
                        }      
                       
                        p++;
                               
                        if(!(bitmask >>= 1)) bitmask = 0x80;                                    
                }
                   
                p = rowStart;
                p.OffsetY(pixData, 1);
                                       
                src += (data->BitMapModulo - data->Width - data->SrcX) * 4;  
                if(mask) mask += data->MaskModulo;                                      
        }  
       
        printf("out\n");

=================================================================
       
You can see that before the loop "in" is printed and after the loop "out" is printed. Now what happens is this: Sometimes "in" is printed but not "out". Instead of printing "out", the program seems to leave the code above entirely and just return to normal event processing from the main loop because instead of printing "out", the next thing my program does is running the callback installed for EVT_SIZE.

This is confusing the hell out of me. What's going on here? Could it be that the code above throws an exception that causes the function to be left and return back to normal event processing? I'm not really familiar with C++ exceptions and stuff.

Multithreading is involved but both the function above and the EVT_SIZE callback are run on the main thread so there must be something that causes the function above to be interrupted because I never see "out" being printed. Instead, "in" is printed and the next thing I see is EVT_SIZE being called, all on the main thread. How can this happen?

--
Best regards,
 Andreas Falkenhahn                          mailto:[hidden email]

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: Events suddenly triggered while using wxAlphaPixelData

Vadim Zeitlin-4
On Wed, 3 Oct 2018 17:38:37 +0200 Andreas Falkenhahn wrote:

AF> You can see that before the loop "in" is printed and after the loop
AF> "out" is printed. Now what happens is this: Sometimes "in" is printed
AF> but not "out". Instead of printing "out", the program seems to leave
AF> the code above entirely and just return to normal event processing from
AF> the main loop because instead of printing "out", the next thing my
AF> program does is running the callback installed for EVT_SIZE.
AF>
AF> This is confusing the hell out of me. What's going on here? Could it be
AF> that the code above throws an exception that causes the function to be
AF> left and return back to normal event processing? I'm not really
AF> familiar with C++ exceptions and stuff.

 You don't have to be familiar with them to see if any exceptions are
thrown or not. Just run your program under debugger and see if there are
any "first chance exceptions" logged by it (depending on your debugger and
its configuration it may or not stop on them, but it should at least show
them). Of course, if you hadn't done anything special to suppress them, you
should be getting an error message box too...

AF> Instead, "in" is printed and the next thing I see is EVT_SIZE being
AF> called, all on the main thread. How can this happen?

 Basically it can't, at least not with the code you're showing. I'm pretty
sure that if you inject this code into the minimal sample you're not going
to see any such mysteries (you might see a crash though, if your code is
buggy).

 Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/

attachment0 (203 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Events suddenly triggered while using wxAlphaPixelData

oneeyeman
In reply to this post by Andreas Falkenhahn
Hi, Andreas,

On Wed, Oct 3, 2018 at 10:38 AM Andreas Falkenhahn
<[hidden email]> wrote:

>
> Strange things are going on here. I use this code to write raw pixels from a memory buffer to a wxBitmap:
>
> =================================================================
>
>         wxAlphaPixelData pixData(*dstbm, wxPoint(data->DstX, data->DstY), wxSize(data->Width, data->Height));
>         if(!pixData) return;
>
>         wxAlphaPixelData::Iterator p(pixData);
>
>         printf("in\n");
>
>         for(int y = 0; y < data->Height; y++) {
>
>                 int bitmask = 1<<(~data->SrcX&7);
>
>                 src += data->SrcX * 4;
>
>                 wxAlphaPixelData::Iterator rowStart = p;
>
>                 for(int x = 0; x < data->Width; x++) {
>
>                         int enter = 1;
>
>                         if(mask) enter = (mask[(data->SrcX + x)>>3] & bitmask);
>
>                         if(enter) {
>
>                                 if(premultiply) {
>
>                                         UBYTE av = src[a];
>
>                                         p.Red()   = dopremultiply(src[r], av);
>                                         p.Green() = dopremultiply(src[g], av);
>                                         p.Blue()  = dopremultiply(src[b], av);
>
>                                 } else {
>
>                                         p.Red()   = src[r];
>                                         p.Green() = src[g];
>                                         p.Blue()  = src[b];
>                                 }
>
>                                 p.Alpha() = (doalpha) ? src[a] : 255;
>                                 src += 4;
>
>                         } else {
>
>                                 src += 4;
>                         }
>
>                         p++;
>
>                         if(!(bitmask >>= 1)) bitmask = 0x80;
>                 }
>
>                 p = rowStart;
>                 p.OffsetY(pixData, 1);
>
>                 src += (data->BitMapModulo - data->Width - data->SrcX) * 4;
>                 if(mask) mask += data->MaskModulo;
>         }
>
>         printf("out\n");
>
> =================================================================
>
> You can see that before the loop "in" is printed and after the loop "out" is printed. Now what happens is this: Sometimes "in" is printed but not "out". Instead of printing "out", the program seems to leave the code above entirely and just return to normal event processing from the main loop because instead of printing "out", the next thing my program does is running the callback installed for EVT_SIZE.

What are the preconditions for such behaviour?
Is it possible that something from the secondary thread  is doing
something that affects the code you posted? Or maybe you didn't free
the resources/memory somewhere and do have issues now?

Thank you.

>
> This is confusing the hell out of me. What's going on here? Could it be that the code above throws an exception that causes the function to be left and return back to normal event processing? I'm not really familiar with C++ exceptions and stuff.
>
> Multithreading is involved but both the function above and the EVT_SIZE callback are run on the main thread so there must be something that causes the function above to be interrupted because I never see "out" being printed. Instead, "in" is printed and the next thing I see is EVT_SIZE being called, all on the main thread. How can this happen?
>
> --
> Best regards,
>  Andreas Falkenhahn                          mailto:[hidden email]
>
> --
> Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
>
> To unsubscribe, send email to [hidden email]
> or visit http://groups.google.com/group/wx-users

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users