Out of memory when running FPDF_InitLibraryWithConfig on iPad

73 views
Skip to first unread message

M.S.K.Z.

unread,
Jun 20, 2023, 12:42:01 PM6/20/23
to pdfium
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.

geisserml

unread,
Jun 20, 2023, 4:23:21 PM6/20/23
to pdfium
From the stack trace, it looks like you may be using the V8 enabled binaries.
pdfium-binaries patch V8 init into FPDF_InitLibraryWithConfig(). There have been some problems with this in the past (though no iOS specific reports so far).

Have you tried with the default (non-V8) binaries yet?

M.S.K.Z.

unread,
Jun 20, 2023, 8:55:57 PM6/20/23
to pdfium
Thank you for your response.
yes. I downloaded and used the following non-V8 binaries for iOS from pdfium-binaries.
 ・ pdfium-ios-arm64.tgz
 ・ pdfium-ios-x64.tgz
Should I not use this?


> Have you tried with the default (non-V8) binaries yet?
Do you know how to download default (non-V8) binaries?

Thank you

2023年6月21日水曜日 5:23:21 UTC+9 geisserml:

M.S.K.Z.

unread,
Jun 21, 2023, 2:44:22 AM6/21/23
to pdfium
Problem solved. I was able to run it on my iPad.
I built using "build.sh" from pdfium-binaries. When doing the build, I added the "build for musl" build option.

Thank you

2023年6月21日水曜日 9:55:57 UTC+9 M.S.K.Z.:

K. Moon

unread,
Jun 21, 2023, 12:59:30 PM6/21/23
to M.S.K.Z., pdfium
For future reference, the PDFium project doesn't support iOS. You should direct support questions to the pdfium-binaries project, not this one.

--
You received this message because you are subscribed to the Google Groups "pdfium" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdfium+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pdfium/86dbad94-1c58-4037-8b15-dc3120e0c6d8n%40googlegroups.com.

M.S.K.Z.

unread,
Jun 21, 2023, 8:46:50 PM6/21/23
to pdfium
Thank you for your response.
Yes. I'll ask pdfium-binaries project.

2023年6月22日木曜日 1:59:30 UTC+9 km...@chromium.org:
Reply all
Reply to author
Forward
0 new messages