wxPdfDocument crash with image Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
BrokenBrain
Experienced Solver
Experienced Solver
Posts: 79
Joined: Fri Dec 21, 2007 7:52 am
Location: Italy
Contact:

wxPdfDocument crash with image

Post by BrokenBrain » Thu Apr 03, 2008 7:28 am

I'm trying the code samples that come with the library, but every sample with a row like this crash.

Code: Select all

Image(_T("wxpdfdoc.png"),10,8,28);
Any idea? I read some very old post, is it a library bug?

lester
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Sep 02, 2006 7:24 pm
Location: Ukraine

Re: wxPdfDocument crash with image

Post by lester » Thu Apr 03, 2008 7:46 am

BrokenBrain wrote:I'm trying the code samples that come with the library, but every sample with a row like this crash.

Code: Select all

Image(_T("wxpdfdoc.png"),10,8,28);
Any idea? I read some very old post, is it a library bug?
I use:
m_pDocument->Image( _T(""), bmp.ConvertToImage(), x, y );
and this work for me, so You can try load image manually

BrokenBrain
Experienced Solver
Experienced Solver
Posts: 79
Joined: Fri Dec 21, 2007 7:52 am
Location: Italy
Contact:

Post by BrokenBrain » Thu Apr 03, 2008 9:27 am

You suggest to load image myself an so:

Code: Select all

    wxBitmap logo;
    logo = wxBitmap(_T("wxpdfdoc.png"));
But i don't undestand how to pass to Image method.
m_pDocument->Image( _T(""), bmp.ConvertToImage(), x, y );
bool wxPdfDocument::Image ( const wxString & file,
double x,
double y,
double w = 0,
double h = 0,
const wxString & mimeType = wxEmptyString,
const wxPdfLink & link = wxPdfLink(-1),
int maskImage = 0
)

lester
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Sep 02, 2006 7:24 pm
Location: Ukraine

Post by lester » Thu Apr 03, 2008 9:37 am

In my version of wxPdf exist

/**
* Puts an image in the page
* The image is given by an wxImage-Object
* \param name Name of the image to be used as an identifier for this image object.
* \param image wxImage object which will be embedded as PNG
* \param x Abscissa of the upper-left corner.
* \param y Ordinate of the upper-left corner.
* \param w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
* \param h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
* \param link URL or identifier returned by AddLink().
* \param maskImage Id of an image mask created previously by ImageMask().
*/
virtual bool Image(const wxString& name, const wxImage& image,
double x, double y, double w = 0, double h = 0,
const wxPdfLink& link = wxPdfLink(-1),
int maskImage = 0);

utelle
Moderator
Moderator
Posts: 997
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument crash with image

Post by utelle » Thu Apr 03, 2008 9:59 am

BrokenBrain wrote:I'm trying the code samples that come with the library, but every sample with a row like this crash.

Code: Select all

Image(_T("wxpdfdoc.png"),10,8,28);
Any idea? I read some very old post, is it a library bug?
It's very unlikely that it is a library bug. If the sample application crashes on adding an image this usually means that the image file has not been found. Since the file name is given without a path the image file can only be found if you run the application in the same directory where the image file resides.

I have to admit that the error handling in this particular case is suboptimal. I'll change this behaviour in the next release, so that an error message shows up instead of crashing.

BTW which version of wxWidgets and of wxPdfDocument on which platform are you using?

Regards,

Ulrich

BrokenBrain
Experienced Solver
Experienced Solver
Posts: 79
Joined: Fri Dec 21, 2007 7:52 am
Location: Italy
Contact:

Post by BrokenBrain » Thu Apr 03, 2008 10:19 am

I'm using wixwidgets 2.8 and wxPdfDocument 0.8 on Windows XP.

I used the makefile to build samples and without change anything all samples with image crash. Images are in the same directory of the files and so my project, i've copyed also wxpdfdoc.png in the same directory of the exe file, but it doesn't work yet.

utelle
Moderator
Moderator
Posts: 997
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Post by utelle » Thu Apr 03, 2008 11:34 am

BrokenBrain wrote:I'm using wixwidgets 2.8 and wxPdfDocument 0.8 on Windows XP.
This should definitely work. Which compiler do you use? And which build of wxWidgets - that is, ANSI ./. Unicode, static ./. DLL?
BrokenBrain wrote:I used the makefile to build samples and without change anything all samples with image crash. Images are in the same directory of the files and so my project, i've copyed also wxpdfdoc.png in the same directory of the exe file, but it doesn't work yet.
Do you get any error messages?

Could you debug the application to find out at which statement exactly the application crashes?

Many of the samples do not use images. Do these samples work as expected?

Regards,

Ulrich

BrokenBrain
Experienced Solver
Experienced Solver
Posts: 79
Joined: Fri Dec 21, 2007 7:52 am
Location: Italy
Contact:

Post by BrokenBrain » Thu Apr 03, 2008 1:11 pm

Examples without image work fine.
Samples with image crash on Image().

I build library with thesse option

# Use DLL build of wx library to use? [0,1]
WX_SHARED = 1

# Compile Unicode build of wxWidgets? [0,1]
WX_UNICODE = 1

# Use debug build of wxWidgets (define __WXDEBUG__)? [0,1]
WX_DEBUG = 0

# Version of the wx library to build against.
WX_VERSION = 28

# Use monolithic build of wxWidgets? [0,1]
WX_MONOLITHIC = 1


I don't image that it would can be a problem, but when i build i got this error:

"cannot find wxmsw28u_gcc.dll"

Then i rename my one "wxmsw28u_gcc_custom.dll" and i put in the same directory of the exe.

Do you think I have to rebuid to fix it?

BrokenBrain
Experienced Solver
Experienced Solver
Posts: 79
Joined: Fri Dec 21, 2007 7:52 am
Location: Italy
Contact:

Post by BrokenBrain » Thu Apr 03, 2008 3:30 pm

Rebuilding with these option all examples work fine:

# Use DLL build of wx library to use? [0,1]
WX_SHARED = 0

# Compile Unicode build of wxWidgets? [0,1]
WX_UNICODE = 1

# Use debug build of wxWidgets (define __WXDEBUG__)? [0,1]
WX_DEBUG = 1

# Version of the wx library to build against.
WX_VERSION = 28

# Use monolithic build of wxWidgets? [0,1]
WX_MONOLITHIC = 1


But the exe is 30MB so the problem is for the shared option... i don't understand.

utelle
Moderator
Moderator
Posts: 997
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Post by utelle » Thu Apr 03, 2008 4:23 pm

BrokenBrain wrote:Examples without image work fine.
Samples with image crash on Image().
Good. This means either the image file is not found or for some reason the wxWidgets file system handler is not correctly initialized.
BrokenBrain wrote:# Version of the wx library to build against.
WX_VERSION = 28
Which version of wxWidgets exactly? 2.8.7?
BrokenBrain wrote:I don't image that it would can be a problem, but when i build i got this error:

"cannot find wxmsw28u_gcc.dll"

Then i rename my one "wxmsw28u_gcc_custom.dll" and i put in the same directory of the exe.

Do you think I have to rebuid to fix it?
Well, when building wxWidgets you can specify a vendor tag (default: custom). But it seems your vendor tag was empty, since the link library contains a reference to 'wxmsw28u_gcc.dll'.

Do you have more than one wxWidgets version on your computer? Does the environment variable WXWIN point to the right directory?

Regards,

Ulrich

utelle
Moderator
Moderator
Posts: 997
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Post by utelle » Thu Apr 03, 2008 4:39 pm

BrokenBrain wrote:Rebuilding with these option all examples work fine:

# Use DLL build of wx library to use? [0,1]
WX_SHARED = 0
Ok, that means, the problem can't be related to the file path. So probably for some reason the file system handler does not get initialized for some reason.

Please try out adding a call to

wxFileSystem::AddHandler(new wxLocalFSHandler);

in the OnInit method of the sample application and a call to

wxFileSystem::CleanUpHandlers();

in the OnExit method, although this should definitely not be necessary since it's done in the OnInit method of the wxFileSystemModule class on start up of a wxApp.

See also http://forums.wxwidgets.org/viewtopic.php?t=8186.
BrokenBrain wrote:But the exe is 30MB so the problem is for the shared option... i don't understand.
It should definitely work with the shared option.

Make sure there is no mix of different wxWidgets versions. Use of the link libraries matching the DLLs is important.

Regards,

Ulrich

BrokenBrain
Experienced Solver
Experienced Solver
Posts: 79
Joined: Fri Dec 21, 2007 7:52 am
Location: Italy
Contact:

Post by BrokenBrain » Fri Apr 04, 2008 7:47 am

Which version of wxWidgets exactly?
2.8.7

Please try out adding a call to

wxFileSystem::AddHandler(new wxLocalFSHandler);

in the OnInit method of the sample application and a call to

wxFileSystem::CleanUpHandlers();

in the OnExit method, although this should definitely not be necessary since it's done in the OnInit method of the wxFileSystemModule class on start up of a wxApp.
I've done:

Code: Select all

void
tutorial2()
{
  wxFileSystem::AddHandler(new wxLocalFSHandler);
//Instanciation of inherited class
  PdfTuto2 pdf;
  pdf.AliasNbPages();
  pdf.AddPage();
  pdf.Image(_T("smile.jpg"),70,40,12);
  pdf.Image(_T("apple.gif"),110,40,25);
  pdf.SetFont(_T("Times"),_T(""),12);
  int i;
  for (i = 1; i <= 40; i++)
  {
    pdf.Cell(0,10,wxString::Format(_T("Printing line number %d"),i),0,1);
  }
  pdf.SaveAsFile(_T("tutorial2.pdf"));


  wxFileSystem::CleanUpHandlers();

}
But i've the same crash.
Make sure there is no mix of different wxWidgets versions. Use of the link libraries matching the DLLs is important.
I'm searching on it, when I installed wxwidgets i made a lot of tests, i used wxPack, wxdevpack, and codeblocks nightly build, maybe i forgot something. The strange thing is that it all works untill now, with ctb library, mysql library, with postresql library, but I'll see.

Thank you for all your suggestion,
any another il appreciated.[/code]

utelle
Moderator
Moderator
Posts: 997
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Post by utelle » Fri Apr 04, 2008 9:54 am

BrokenBrain wrote:
Which version of wxWidgets exactly?
2.8.7
There should not be a problem using wxPdfDocument with version 2.8.7.
BrokenBrain wrote: I've done:
[...]
But i've the same crash.
What a pity. :(

I fear you'll have to debug the application to identify the exact place where the program crashes.
BrokenBrain wrote: I'm searching on it, when I installed wxwidgets i made a lot of tests, i used wxPack, wxdevpack, and codeblocks nightly build, maybe i forgot something. The strange thing is that it all works untill now, with ctb library, mysql library, with postresql library, but I'll see.
Usually builds of the same wxWidgets version should be binary compatible, but if slightly different configuration options were used this might not be the case.

But as long as it is not clear what exactly is causing the crash this is all wild guessing only.
BrokenBrain wrote: Thank you for all your suggestion,
any another il appreciated.
At the moment I can't suggest anything else than to debug the application to find out the statement/method where the crash happens. This will allow further investigation.

Regards,

Ulrich

BrokenBrain
Experienced Solver
Experienced Solver
Posts: 79
Joined: Fri Dec 21, 2007 7:52 am
Location: Italy
Contact:

Post by BrokenBrain » Fri Apr 04, 2008 3:51 pm

I uninstalled wxPack.
I rebuilded wxwidgets.

I don't know whiy but i could not compile wxpdfdoc with debug option it says cannot find setup.h
Then i compiled with theese option.

# Use DLL build of wx library to use? [0,1]
WX_SHARED = 1

# Compile Unicode build of wxWidgets? [0,1]
WX_UNICODE = 1

# Use debug build of wxWidgets (define __WXDEBUG__)? [0,1]
WX_DEBUG = 0

# Version of the wx library to build against.
WX_VERSION = 28

# Use monolithic build of wxWidgets? [0,1]
WX_MONOLITHIC = 1


and it seems to work!

And so i'll pass thi weekend in peace :P

Thank you for your precious suggests.

utelle
Moderator
Moderator
Posts: 997
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Post by utelle » Fri Apr 04, 2008 6:38 pm

BrokenBrain wrote:I rebuilded wxwidgets.

I don't know whiy but i could not compile wxpdfdoc with debug option it says cannot find setup.h
This is a wxWidgets issue. When you build wxWidgets a setup.h is written to a subdirectory of the wxWidgets lib directory. If wxWidgets was not build for debugging the corresponding include file will not be there.
BrokenBrain wrote:Then i compiled with theese option.
[...]
and it seems to work!
Great. :D

Feel free to contact me if further questions arise in using wxPdfDocument or if you have any suggestions for improving wxPdfDocument.

Regards,

Ulrich

Post Reply