Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashed when closing app #2572

Closed
qsyttkx opened this issue Dec 8, 2022 · 5 comments
Closed

Crashed when closing app #2572

qsyttkx opened this issue Dec 8, 2022 · 5 comments

Comments

@qsyttkx
Copy link

qsyttkx commented Dec 8, 2022

scene:

When the main function is returned, a detached thread print a log, then crashed(probabilistic occurrence).

version: spdlog-1.10.0

crashed message:

Unhandled exception thrown: read access violation.
_Mem was 0x50.

crashed stack:

std::_Atomic_storage<int,4>::load(const std::memory_order _Order) Line 912 (c:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\atomic:912)
spdlog::logger::should_log(spdlog::level::level_enum msg_level) Line 303 (d:\Projects\litchi\3rd\spdlog-1.10.0\include\spdlog\logger.h:303)
spdlog::logger::log_<std::string &>(spdlog::source_loc loc, spdlog::level::level_enum lvl, fmt::v8::basic_string_view<char> fmt, std::string & <args_0>) Line 358 (d:\Projects\litchi\3rd\spdlog-1.10.0\include\spdlog\logger.h:358)
spdlog::logger::log<std::string &>(spdlog::source_loc loc, spdlog::level::level_enum lvl, fmt::v8::basic_format_string<char,std::string &> fmt, std::string & <args_0>) Line 91 (d:\Projects\litchi\3rd\spdlog-1.10.0\include\spdlog\logger.h:91)
my_function

How to avoid it?

@tt4g
Copy link
Contributor

tt4g commented Dec 8, 2022

Try calling spdlog::shutdown() before exiting the application.

@qsyttkx
Copy link
Author

qsyttkx commented Dec 9, 2022

Try calling spdlog::shutdown() before exiting the application.

I call spdlog::drop_all() before main() return, and it will still crash when I change it to spdlog::shutdown.

But, thank you, I found that printing logs after shutdown called triggers the crash. So I just removed drop_all/shutdown, and I am now at peace.

Is it a bug that needs to be fixed? (check if shutdown is called before logging)

@qsyttkx qsyttkx closed this as completed Dec 9, 2022
@tt4g
Copy link
Contributor

tt4g commented Dec 9, 2022

Is it a bug that needs to be fixed? (check if shutdown is called before logging)

No. It is by design that spdlog crashes after calling these APIs.

@beautifulnight
Copy link

beautifulnight commented Jul 19, 2023

I found that i need to call drop_all to reset the shared_ptr so that the registry can be destructed, otherwise the use_count of the default_logger_ will not be zero and lead to memory leak. Is that a problem or I got something wrong?

@tt4g
Copy link
Contributor

tt4g commented Jul 19, 2023

@beautifulnight It is better to call, but the registry is a static variable in the function, so memory should be released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants