galkahana / PDF-Writer

High performance library for creating, modiyfing and parsing PDF files in C++
http://www.pdfhummus.com
Apache License 2.0
885 stars 210 forks source link

Seg Fault #275

Closed 7Towers closed 2 weeks ago

7Towers commented 3 weeks ago

I'm seeing a seg fault on OSX (Sonoma 14.6.1, M3) and Windows 11 with the most basic of implementations.

Is this a known issue?

Logs

ermination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [7725]

VM Region Info: 0 is not in any region.  Bytes before following region: 4378542080
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                      104fb4000-105330000    [ 3568K] r-x/r-x SM=COW  /Users/USER/*/appInspectFast.app/Contents/MacOS/appInspectFast

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   appInspectFast                         0x1050f918c ObjectsContext::StartNewIndirectObject() + 52 (ObjectsContext.cpp:320)
1   appInspectFast                         0x1050a3c2c PDFHummus::DocumentContext::WriteCatalogObject(ObjectReference const&, IDocumentContextExtender*) + 44 (DocumentContext.cpp:501)
2   appInspectFast                         0x1050a2b2c PDFHummus::DocumentContext::WriteCatalogObjectOfNewPDF() + 116 (DocumentContext.cpp:494)
3   appInspectFast                         0x1050a288c PDFHummus::DocumentContext::FinalizeNewPDF() + 128 

Source Example

#include <PDFPage.h>
#include <PDFWriter.h>
#include <iostream>
#include <unistd.h>

using namespace std;

int main()
{
    cout << "Hello PDF Writer" << endl;
    // get current path
    char path[256];
    getcwd(path, sizeof(path));
    PDFWriter pdfWriter;
    pdfWriter.StartPDF(path, ePDFVersion13);
    PDFPage* page = new PDFPage();
    page->SetMediaBox(PDFRectangle(0,0,595,842));
    pdfWriter.WritePage(page);
    delete page;
    auto result = pdfWriter.EndPDF();
    if (result == PDFHummus::eFailure) {
        cout << "Failed to create PDF" << endl;
    } else {
        cout << "PDF created successfully at " << path << endl;
    }
    return 0;
}

cmake_minimum_required(VERSION 3.16)

project(SimplePDF LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)

FetchContent_Declare(
    PDFHummus
    GIT_REPOSITORY https://github.com/galkahana/PDF-Writer.git
    GIT_TAG v4.6.5
    FIND_PACKAGE_ARGS
)

FetchContent_MakeAvailable(PDFHummus)

add_executable(SimplePDF main.cpp)

target_link_libraries(SimplePDF PRIVATE PRIVATE PDFHummus::PDFWriter)

include(GNUInstallDirs)
install(TARGETS SimplePDF
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
galkahana commented 3 weeks ago

you provided a folder path instead of a file path. try providing a file path instead. should work better. note that you can get some help with:

7Towers commented 1 week ago

Thanks @galkahana Providing the file path resolves the issue. Well done. Solid library. Thanks for your work.