Traverse-Research / gpu-allocator

🦀 GPU memory allocator for Vulkan, DirectX 12 and Metal. Written in pure Rust
https://traverse.nl/
Apache License 2.0
380 stars 50 forks source link

Replace `backtrace` crate with stabilized `std::backtrace` implementation #186

Closed MarijnS95 closed 1 year ago

MarijnS95 commented 1 year ago

Sticking to my promise of updating and submitting this old branch in #183.

Fixes #183 (by no longer using the backrace/cc crate); Fixes #184 (the old approach from that branch).


Rust 1.65 stabilized std::backtrace::Backtrace, which we can use in place of the backtrace crate to reduce our dependency stack.

Normally Backtrace::capture() would listen to the RUST_BACKTRACE and RUST_LIB_BACKTRACE environment variables, but this is unsuitable for us as capturing backtraces is configured via boolean debug feature flags in the AllocatorDebugSettings struct. Fortunately Backtrace::force_capture() exists which circumvents these env var checks and always returns a backtrace, and is hence used in the codebase here.

Unfortuantely the type no longer implements Clone like backtrace::Backtrace, requiring us to wrap it in an Arc (because most of our types are thread-safe) to clone the Backtrace around various (sub)allocations and statistics reports.

Jasper-Bekkers commented 1 year ago

I'm not comfortable having the stack trace collection of this crate be dependent on a rust specific environment variable. This is a feature of this crate and should thus be controlled by us / users of this crate directly from code.

MarijnS95 commented 1 year ago

@Jasper-Bekkers the comment exactly explains that that is the reason that Backtrace::force_capture() is used over Backtrace::capture(), because the former ignores Rust-specific environment variables. I see now that that comment wasn't super clear, so I've completely rewritten that paragraph, thanks for highlighting this :+1: