wxPdfFontManager not initialized  [SOLVED]

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 269
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

wxPdfFontManager not initialized

Postby mael15 » Tue Sep 04, 2018 1:29 pm

Hi,
I have a similar error as this one:
https://forums.wxwidgets.org/viewtopic.php?t=39815
The ms_fontManager ist nullptr because wxPdfDocumentModule::OnInit() is not called.

This is how I want to use it:

Code: Select all

wxPdfDocument pdfDcmt;
wxFont defaultFont(wxFontInfo(10).Family(wxFONTFAMILY_DEFAULT).Underlined(false));
wxPdfFont pdfArialFont = wxPdfFontManager::GetFontManager()->RegisterFont(defaultFont, wxT("Arial"));
bool ok = pdfDcmt.SetFont(pdfArialFont);

What might be wrong?

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

Re: wxPdfFontManager not initialized

Postby utelle » Tue Sep 04, 2018 8:28 pm

mael15 wrote:Hi,
I have a similar error as this one:
https://forums.wxwidgets.org/viewtopic.php?t=39815
The ms_fontManager ist nullptr because wxPdfDocumentModule::OnInit() is not called.

This is how I want to use it:

Code: Select all

wxPdfDocument pdfDcmt;
wxFont defaultFont(wxFontInfo(10).Family(wxFONTFAMILY_DEFAULT).Underlined(false));
wxPdfFont pdfArialFont = wxPdfFontManager::GetFontManager()->RegisterFont(defaultFont, wxT("Arial"));
bool ok = pdfDcmt.SetFont(pdfArialFont);

What might be wrong?

Most likely either your wxWidgets library or your application is not set up properly. The OnInit and OnExit methods of a wxModule should be called automatically on initialization of wxWidgets. If that does not happen, it is not a wxPdfDocument issue, but a wxWidgets or application issue.

You could adjust method wxPdfFontManager::GetFontManager() to check the pointer ms_fontManager and to instantiate a wxFontManager if it is null. However, the drawback is that you would get a memory leak, because the wxFontManager instance would never be freed. And this workaround would not solve the underlying problem.

wxWidgets itself uses the wxModule mechanism in many places. Therefore your application would not work at all, if the mechanism wouldn't work at all.

You don't tell on which platform with which wxWidgets version you are developing and how you built wxPdfDocument. On Windows you may run into trouble for example if you built wxPdfDocument as a DLL which links against a static wxWidgets library. That would result most likely in more than one instance of the wxWidgets library of which only one would be properly initialized.

My guess is that your application somehow uses 2 (or more?) different wxWidgets library instances of which only one is initialized, and your build of wxPdfDocument references the uninitialized instance.

Regards,

Ulrich

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 269
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: wxPdfFontManager not initialized  [SOLVED]

Postby mael15 » Fri Sep 14, 2018 7:54 am

Thank you!
After many tests I found out that it works fine in MSW wxWidgets 3.1.0 but fails in 3.1.1.
I did not have time to figure out the specific problem and just reverted back to 3.1.0.
I do use wxPdfDocument as a dll so I guess what you described with different instances and just one being initialised could have played a role there.

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

Re: wxPdfFontManager not initialized

Postby utelle » Fri Sep 14, 2018 1:07 pm

mael15 wrote:After many tests I found out that it works fine in MSW wxWidgets 3.1.0 but fails in 3.1.1.

This is very strange, because I use wxPdfDocument myself together with wxWidgets 3.1.1 without any problems.

mael15 wrote:I did not have time to figure out the specific problem and just reverted back to 3.1.0.
I do use wxPdfDocument as a dll so I guess what you described with different instances and just one being initialised could have played a role there.

I use wxPdfDocument as a DLL, too. So, most likely there is something wrong with your wxWidgets 3.1.1 installation, but I have no idea what might have gone wrong.

Regards,

Ulrich

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 269
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: wxPdfFontManager not initialized

Postby mael15 » Fri Sep 14, 2018 2:44 pm

Could very well be that I did not rebuild wxPdfDoc with 3.1.1 but used a 3.1.0 build with my 3.1.1 app? Anyway, works fine again now. Thanx!


Return to “wxCode”

Who is online

Users browsing this forum: No registered users and 0 guests