I am creating a PDFViewer with Xamarin.iOS. And I'm using PDFium for PDF rendering.
The PDFium library for iOS is downloaded and used below.
Use the downloaded libpdfium.dylib to create a delegate using a combination of dlopen/dlsym and Marshal.GetDelegateForFunctionPointer and pass it.
When I build and run it, it works fine in iOS Simulator, but Out of memory occurs on iPad.
Do you know the reason?
// Sample Source
[StructLayout(LayoutKind.Sequential)]
public class FPDF_LIBRARY_CONFIG
{
public int version;
public IntPtr m_pUserFontPaths;
public IntPtr m_pIsolate;
public uint m_v8EmbedderSlot;
public IntPtr m_pPlatform;
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void FPDF_InitLibraryWithConfigDelegate([MarshalAs(UnmanagedType.LPStruct)] FPDF_LIBRARY_CONFIG config);
public static void TestFunc()
{
var config = new FPDF_LIBRARY_CONFIG {
version = 2,
m_pUserFontPaths = IntPtr.Zero,
m_pIsolate = IntPtr.Zero,
m_v8EmbedderSlot = 0,
m_pPlatform = IntPtr.Zero,
};
// Where /full/path/to/ is the full path to the Dylib being consumed.
var dllHandle = ObjCRuntime.Dlfcn.dlopen("/full/path/to/libpdfium.dylib", 1);
var handle = ObjCRuntime.Dlfcn.dlsym(dllHandle, "FPDF_InitLibraryWithConfig");
if (handle == IntPtr.Zero) {
throw new Exception();
}
var pdfiumDelegate = Marshal.GetDelegateForFunctionPointer<FPDF_InitLibraryWithConfigDelegate>(handle);
// This is where Out of memory occurs.
pdfiumDelegate(config);
}
// Stack Trace
#
# Fatal error in , line 0
# Fatal process out of memory: Oilpan: CagedHeap reservation.
#
#
#
#FailureMessage Object: 0x16f48b818
==== C stack trace ===============================
0 libpdfium.dylib 0x000000016172ea44 v8::base::debug::StackTrace::StackTrace() + 24
1 libpdfium.dylib 0x0000000161731578 v8::platform::(anonymous namespace)::PrintStackTrace() + 24
2 libpdfium.dylib 0x0000000161725b24 V8_Fatal(char const*, ...) + 268
3 libpdfium.dylib 0x0000000160f4714c v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) + 116
4 libpdfium.dylib 0x00000001610b2988 v8::internal::CppHeap::DetachIsolate() + 0
5 libpdfium.dylib 0x00000001614b71e8 cppgc::internal::FatalOutOfMemoryHandler::operator()(std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>> const&, v8::SourceLocation const&) const + 48
6 libpdfium.dylib 0x00000001614be37c __branred + 0
7 libpdfium.dylib 0x00000001614be0dc cppgc::internal::CagedHeap::InitializeIfNeeded(v8::PageAllocator&) + 76
8 libpdfium.dylib 0x00000001614b72a8 cppgc::InitializeProcess(v8::PageAllocator*) + 72
9 libpdfium.dylib 0x0000000160da9178 FPDF_InitLibraryWithConfig + 92
/////////////////
Thank you.