Segmentation Fault When Finding Black Point
Hi I am trying to run this project on ubuntu 20.04 I have successfully built the project following the instructions but when processing the RAW images I get a segmentation fault. It occurs exactly at the point code tries to find the Black Level from the metadata.
Here is my shell code output
[nix-shell:~/Code/hdr-plus/build]$ ./hdrplus dir_path out_img.png burst0_0.CR2 burst0_1.CR2
Opening dir_path/burst0_0.CR2
Opening dir_path/burst0_1.CR2
Black point: Segmentation fault (core dumped)
Any idea how to solve this?
I'll try and look at this issue this week, thank you for the report!
I can reproduce this issue locally. I'll start investigating.
Edit:
lldb:
Process 128835 launched: '/home/primary/projects/hdr-plus/build/hdrplus' (x86_64)
Opening ./../burst1_2.CR2
Opening ./../burst1_7.CR2
Black point: Process 128835 stopped
* thread #1, name = 'hdrplus', stop reason = signal SIGSEGV: address not mapped to object (fault address: 0x300000020)
frame #0: 0x000000000040a3c7 hdrplus`RawImage::GetBlackLevel() const + 7
hdrplus`RawImage::GetBlackLevel:
-> 0x40a3c7 <+7>: movq 0x20(%rdi), %rsi
0x40a3cb <+11>: movl $0x2daa8, %edx ; imm = 0x2DAA8
0x40a3d0 <+16>: movq %fs:0x28, %rax
0x40a3d9 <+25>: movq %rax, 0x2dab8(%rsp)
code in question:
std::array<float, 4> RawImage::GetBlackLevel() const {
// See https://www.libraw.org/node/2471
const auto raw_color = RawProcessor->imgdata.color;
const auto base_black_level = static_cast<float>(raw_color.black);
std::array<float, 4> black_level = {
base_black_level + static_cast<float>(raw_color.cblack[0]),
base_black_level + static_cast<float>(raw_color.cblack[1]),
base_black_level + static_cast<float>(raw_color.cblack[2]),
base_black_level + static_cast<float>(raw_color.cblack[3])};
if (raw_color.cblack[4] == 2 && raw_color.cblack[5] == 2) {
for (int x = 0; x < raw_color.cblack[4]; ++x) {
for (int y = 0; y < raw_color.cblack[5]; ++y) {
const auto index = y * 2 + x;
black_level[index] = raw_color.cblack[6 + index];
}
}
}
return black_level;
}
Edit 2: The issue has to do with RawProcessor. I'm investigating the api.
I find HDRPlus holding the reference of temporary object created in constructor function causes this fault. Changing type to "const Burst&" can fix this issue
https://github.com/BlueMatthew/hdr-plus/commit/03dfddd892d0aaf066e54a52bbf7e2765f75e71b
I can reproduce this issue locally. I'll start investigating.
Edit:
lldb:
Process 128835 launched: '/home/primary/projects/hdr-plus/build/hdrplus' (x86_64) Opening ./../burst1_2.CR2 Opening ./../burst1_7.CR2 Black point: Process 128835 stopped * thread #1, name = 'hdrplus', stop reason = signal SIGSEGV: address not mapped to object (fault address: 0x300000020) frame #0: 0x000000000040a3c7 hdrplus`RawImage::GetBlackLevel() const + 7 hdrplus`RawImage::GetBlackLevel: -> 0x40a3c7 <+7>: movq 0x20(%rdi), %rsi 0x40a3cb <+11>: movl $0x2daa8, %edx ; imm = 0x2DAA8 0x40a3d0 <+16>: movq %fs:0x28, %rax 0x40a3d9 <+25>: movq %rax, 0x2dab8(%rsp)code in question:
std::array<float, 4> RawImage::GetBlackLevel() const { // See https://www.libraw.org/node/2471 const auto raw_color = RawProcessor->imgdata.color; const auto base_black_level = static_cast<float>(raw_color.black); std::array<float, 4> black_level = { base_black_level + static_cast<float>(raw_color.cblack[0]), base_black_level + static_cast<float>(raw_color.cblack[1]), base_black_level + static_cast<float>(raw_color.cblack[2]), base_black_level + static_cast<float>(raw_color.cblack[3])}; if (raw_color.cblack[4] == 2 && raw_color.cblack[5] == 2) { for (int x = 0; x < raw_color.cblack[4]; ++x) { for (int y = 0; y < raw_color.cblack[5]; ++y) { const auto index = y * 2 + x; black_level[index] = raw_color.cblack[6 + index]; } } } return black_level; }Edit 2: The issue has to do with RawProcessor. I'm investigating the api.
Great find @BlueMatthew! Fixed in: https://github.com/timothybrooks/hdr-plus/commit/3429723c204000ebfd9fc59792b62236448c167d