#15394 closed defect (fixed)

Loading an image file with wrong format results in errors but the file is still loaded

Reported by: cbowen Owned by:
Priority: low Milestone:
Component: wxGTK Version: 2.9.5
Keywords: png image loading Cc:
Blocked By: Blocking:
Patch: no

Description

I have code that worked fine under 2.8, but I'm having a problem updating to 2.9.5. I get a popup error message stating: 'Failed to load image from file "images/toolbar1.png".' If I expand details, I get: "This is an a XPM file" and "Failed to load image from file "images/toolbar1.png".' The image does, however, load and display correctly.

I am also getting these GLib warnings:

(step2:3123): GLib-GObject-WARNING : /build/buildd/glib2.0-2.32.3/./gobject/gsignal.c:2572: instance 0x2226ab0' has no handler with id 678'

(step2:3123): GLib-GObject-WARNING : /build/buildd/glib2.0-2.32.3/./gobject/gsignal.c:2572: instance 0x216ed00' has no handler with id 595'

(step2:3123): GLib-GObject-WARNING : /build/buildd/glib2.0-2.32.3/./gobject/gsignal.c:2572: instance 0x2114e80' has no handler with id 455'

(step2:3123): GLib-GObject-WARNING : /build/buildd/glib2.0-2.32.3/./gobject/gsignal.c:2572: instance 0x2114800' has no handler with id 309'

I have built the library both with and without --with-libpng=builtin. Results are the same in either case. I am runnning under Ubuntu 12.04 LTS. The only libpng I see is 1.2.

Attachments (1)

toolbar1.png download (79.9 KB) - added by cbowen 16 months ago.
File that can cause problem

Download all attachments as: .zip

Change History (7)

comment:1 Changed 16 months ago by vadz

  • Priority changed from blocker to normal
  • Status changed from new to infoneeded_new

We need a way to reproduce this. Does it happen with a particular image only? If so, can you reproduce the problem in the image sample (it has a menu command to load an image file)?

Changed 16 months ago by cbowen

File that can cause problem

comment:2 Changed 16 months ago by cbowen

  • Status changed from infoneeded_new to new

The problem can't be reproduced using the image sample because I am loading it as a wxBitmap, not as a wxImage. Here is how to produce the error with the minimum amount of code using the image I have included:

#include <wx/wx.h>

class CApp : public wxApp
{
public:

virtual bool OnInit();

};

IMPLEMENT_APP(CApp)

bool CApp::OnInit()
{

if(!wxApp::OnInit()) {

return false;

}


wxInitAllImageHandlers();

wxBitmap bitmap;
if(!bitmap.LoadFile(L"toolbar1.png")) {

wxMessageBox(L"Unable to toolbar1.png");

}


return true;

}

comment:3 Changed 16 months ago by pcor

The default wxBitmapType for wxBitmap::LoadFile() on wxGTK is XPM. You need to specify the correct type:

bitmap.LoadFile("toolbar1.png", wxBITMAP_TYPE_PNG)

It worked with the wrong type in 2.8 more or less by accident.

comment:4 follow-up: Changed 16 months ago by vadz

  • Priority changed from normal to low
  • Status changed from new to confirmed
  • Summary changed from File to load image from file error when load is successful to Loading an image file with wrong format results in errors but the file is still loaded

Hmm, I have no idea why did this change since 2.8. But in any case, we probably don't want to change it back -- if you want format autodetection you can already pass wxBITMAP_TYPE_ANY and presumably we don't want to do this by default for performance reasons (?) as otherwise we'd use wxBITMAP_TYPE_ANY as wxBITMAP_DEFAULT_TYPE everywhere.

Anyhow, the fact that LoadFile() returns true yet gives error messages is a problem. I think wxGTK needs to either do the same thing as wxMSW, i.e. find the handler for this bitmap type and then use this handler to load the file without falling back to gdk_pixbuf_new_from_file(), or, on the contrary, use gdk_pixbuf_new_from_file() first which would be also more consistent with wxMSW as it tries the native functions loading bitmaps from resources first, before falling back to wxImage.

Paul, do you see any reason to not call gdk_pixbuf_new_from_file() first?

comment:5 in reply to: ↑ 4 Changed 16 months ago by pcor

Replying to vadz:

Hmm, I have no idea why did this change since 2.8.

Because I changed it to try wxImage first, on the theory that it supports more formats. Not sure that was such a great theory.

I think wxGTK needs to either do the same thing as wxMSW, i.e. find the handler for this bitmap type and then use this handler to load the file without falling back to gdk_pixbuf_new_from_file(),

There are no handlers, no point in having them, they would all just call gdk_pixbuf_new_from_file() anyway.

Paul, do you see any reason to not call gdk_pixbuf_new_from_file() first?

Only that the bitmap type is silently ignored...

comment:6 Changed 16 months ago by PC

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

(In [74645]) Try native method first in LoadFile() and SaveFile()
closes #15394

Note: See TracTickets for help on using tickets.