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
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.