{"action":"closed","issue":{"url":"https://api.github.com/repos/mmp/pbrt-v3/issues/83","repository_url":"https://api.github.com/repos/mmp/pbrt-v3","labels_url":"https://api.github.com/repos/mmp/pbrt-v3/issues/83/labels{/name}","comments_url":"https://api.github.com/repos/mmp/pbrt-v3/issues/83/comments","events_url":"https://api.github.com/repos/mmp/pbrt-v3/issues/83/events","html_url":"https://github.com/mmp/pbrt-v3/issues/83","id":171264857,"number":83,"title":"Occassional segfault as pbrt exits","user":{"login":"stephenlombardi","id":259593,"avatar_url":"https://avatars.githubusercontent.com/u/259593?v=3","gravatar_id":"","url":"https://api.github.com/users/stephenlombardi","html_url":"https://github.com/stephenlombardi","followers_url":"https://api.github.com/users/stephenlombardi/followers","following_url":"https://api.github.com/users/stephenlombardi/following{/other_user}","gists_url":"https://api.github.com/users/stephenlombardi/gists{/gist_id}","starred_url":"https://api.github.com/users/stephenlombardi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stephenlombardi/subscriptions","organizations_url":"https://api.github.com/users/stephenlombardi/orgs","repos_url":"https://api.github.com/users/stephenlombardi/repos","events_url":"https://api.github.com/users/stephenlombardi/events{/privacy}","received_events_url":"https://api.github.com/users/stephenlombardi/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-08-15T21:21:36Z","updated_at":"2016-08-18T19:27:27Z","closed_at":"2016-08-18T19:27:27Z","body":"I've been getting some randomly-occuring segfaults as pbrt is shutting down after profiling information is printed. There is no problem with the output images at all. I managed to track it down in gdb to https://github.com/mmp/pbrt-v3/blob/master/src/core/stats.cpp:209\r\n\r\n```\r\nThread 1 \"pbrt\" received signal SIGSEGV, Segmentation fault.\r\nReportProfileSample () at /home/steve/pbrt-v3/src/core/stats.cpp:209\r\n215\t    if (profileSamples) profileSamples[ProfilerState]++;\r\n(gdb) print profileSamples\r\n$1 = std::unique_ptr<std::atomic<unsigned long>> containing 0x7ffff7f48010\r\n(gdb) print ProfilerState\r\n$2 = 0\r\n(gdb) bt\r\n#0  ReportProfileSample () at /home/steve/pbrt-v3/src/core/stats.cpp:209\r\n#1  <signal handler called>\r\n#2  0x00007ffff6e43bd9 in brk () from /usr/lib/libc.so.6\r\n#3  0x00007ffff6e43cb9 in sbrk () from /usr/lib/libc.so.6\r\n#4  0x00007ffff6dde749 in __default_morecore () from /usr/lib/libc.so.6\r\n#5  0x00007ffff6dd833a in systrim.isra () from /usr/lib/libc.so.6\r\n#6  0x00007ffff6dd9547 in _int_free () from /usr/lib/libc.so.6\r\n#7  0x00007ffff6d99be8 in __run_exit_handlers () from /usr/lib/libc.so.6\r\n#8  0x00007ffff6d99c35 in exit () from /usr/lib/libc.so.6\r\n#9  0x00007ffff6d84748 in __libc_start_main () from /usr/lib/libc.so.6\r\n#10 0x00000000004725f9 in _start ()\r\n```\r\n\r\nI poked around a bit to try to find the cause, I think it's happening because ReportProfileSamples is being called after profileSamples is destructed or partially destructed. I suspect this because I modified stats.cpp to include the following:\r\n\r\n```\r\nstruct D {\r\n    void operator()(std::atomic<uint64_t>* p){\r\n        delete[] p;\r\n        std::cout << \"destructed!\" << std::endl;\r\n    }\r\n};\r\nstatic std::unique_ptr<std::atomic<uint64_t>[], D> profileSamples;\r\n```\r\n\r\nBefore pbrt segfaults it shows the text, \"destructed!\". I'm not sure what is going on exactly. I've been able to reproduce this consistently with one pbrt file, although I can't really provide it as it relies on some additional light types I've added to PBRT. I haven't modified the profiling system, however. I can test some potential solutions if anyone has any ideas."}}
{"actor":{"display_login":"mmp"}}