Skip to content

[Bug report] Progress callback function gets destroyed #199

@fwanderse

Description

@fwanderse

Describe the bug
I was testing the new Progress & Cancel API and I think I found an issue where the registered callback function gets destroyed in error.

I configured a "Progress/Cancel callback" function using the ContextBuilder, created a Context and then a Builder from it. At the time the Builder was used to sign an a file, an error occurs when the SDK tries to invoke the callback function because the callback std::function has been destroyed.

Exception thrown: read access violation. _Impl was 0xFFFFFFFFFFFFFFFF.
occurs in progress_callback_trampoline function in c2pa.cpp.

To Reproduce
Use a function to create a builder similar to the one below. This function returns a Builder, but the Context used to create the builder goes out of scope and becomes destroyed.

c2pa::Builder CreateBuilder()
{
    // some code 
    
    auto context = c2pa::Context::ContextBuilder()
        .with_json(jsonSettings.dump())
        .with_progress_callback([](c2pa::ProgressPhase phase, uint32_t step, uint32_t total) {
        std::cout << "Progress: " << static_cast<int>(phase) << " " << step << "/" << total << std::endl;
        return true; // Return false to cancel the operation
            })
        .create_context();

    return c2pa::Builder(context, jsonManifestDefinition.dump());
}

Attachments
N/A

Expected behavior
Progress callback to work event if Context object got destroyed after the Builder was created.

It is stated here in the documentation that Context does not need to outlive the Builder created from it.

Desktop (please complete the following information):

  • OS: Windows 10
  • SDK version: v0.22.0
  • Build configuration [e.g. compiler version]: Visual Studio 2026
  • Builds steps: N/A

Additional context
N/A

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions