Opened 2 years ago

Closed 2 years ago

#14643 closed defect (fixed)

LoadImageFromResource pops up spurious warning dialog when alpha channel present

Reported by: Jive Dadson Owned by:
Priority: normal Milestone:
Component: wxMSW Version: stable-latest
Keywords: wxImage LoadImageFromResource InitAlpha Debug Cc:
Blocked By: Blocking:
Patch: no

Description

When running the Debug version, LoadImageFromResource pops up a spurious warning dialog if the resource has an alpha channel. I did not notice that it was a warning until I debugged through the wxWidgets code. I thought my app was crashing.

A possible fix is to change image.cpp, on or about line 2310, to read

if(!image.HasAlpha())
{

image.InitAlpha();

}

The other option is to have wxImage::InitAlpha return quietly if the alpha channel is already present.

To reproduce the defect, find an icon that has an alpha channel, say, "my_icon.ico". In the .rc file,

my_icon ICON "my_icon.ico"

In the application code,

wxBitmap bmp(wxString("my_icon"), wxBITMAP_TYPE_ICO_RESOURCE);

Attachments (2)

folder-my-pictures44x44.ico download (11.6 KB) - added by Jive Dadson 2 years ago.
my_icon.ico download (11.6 KB) - added by Jive Dadson 2 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 2 years ago by Jive Dadson

  • Component changed from base to GUI-all

Changed 2 years ago by Jive Dadson

Changed 2 years ago by Jive Dadson

comment:2 Changed 2 years ago by vadz

  • Component changed from GUI-all to wxMSW
  • Status changed from new to confirmed

Thanks, we indeed should just avoid calling InitAlpha() if we already have it. Will commit soon.

P.S. We currently have a problem with Trac email notifications for the tickets from people with spaces in their names. I'd strongly advise you to register again using a different account, without spaces in its name to ensure that any other tickets you open are noticed. Sorry for the inconvenience.

comment:3 Changed 2 years ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [72471]) Don't initialize alpha twice when loading wxImage from resources.

Calling InitAlpha() when we already had loaded alpha from the resource data
results in an assert. Fix this by only initializing alpha if don't have it
yet.

Closes #14643.

Note: See TracTickets for help on using tickets.