0

I am using VS 2022 Community Edition (v17.3.3) to build wxWidgets application (v3.2.0) using C++ (v14.3 - Features from Latest C++). The windows SDK is using the latest installed (10.0.22621). The project is also using C++ modules.

The Debug build succeeds but when I run the project's exe file at random it throws the exception (Access violation reading 0xFFFFFF (ucrtbased.dll)) in exe_common.inl at the following line:

__scrt_current_native_startup_state = __scrt_native_startup_state::initialized;

After a few more compilations (by just making minor changes to trigger a compilation) it succeeds and the exe runs correctly.

I wonder if there is any settings that might be causing this random error. Btw, I am using Win11 but same thing happens on Win10 as well.

Thanks in advance.

EDIT 1:

The project is using boost libraries and at startup boost/json (boost/json is used in other parts of the project as well). Debugger shows that after the following line the above error happens:

static allocator_arg_t allocator_arg = BOOST_CONTAINER_DOC1ST(unspecified, *std_allocator_arg_holder<>::dummy);
macroland
  • 973
  • 9
  • 27
  • 1
    Have you tried investigating the issue using your [debugger](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) yet? If not, then that should be your first thing to do. – Jesper Juhl Sep 06 '22 at 09:50
  • Yes, that's where the debugger stops at `__scrt_current_native_startup_state = __scrt_native_startup_state::initialized;` – macroland Sep 06 '22 at 09:51
  • If you unwind the stack frames (in the stack frame window) do you get back to your code ? If so inspect the variables in that stack frame. – Richard Critten Sep 06 '22 at 11:25
  • @RichardCritten: I think this problem has started since switching to modules in C++ and currently trialing on disabling "multi-processor compilation" and so far the problem did not happen "yet". – macroland Sep 06 '22 at 12:02
  • @macroland, can you try to build with earlier version of MSVC? I think there was a post recently that proves the version is buggy... – Igor Sep 06 '22 at 12:54
  • @Igor: The project uses several features of C++20 so would be very hard to try with earlier versions. "So far" I am quite convinced that "multi-processor compilation" and modules (I am using module partitions) might cause some trouble, not sure though. – macroland Sep 06 '22 at 13:08
  • The error still happens but its frequency is less, so turning off "multi-processor compilation" helped to some extent but not completely solved the problem. – macroland Sep 06 '22 at 19:50
  • I found that the OS you are using is windows11 but using the win10 SDK, I suggest you install and use the win11 SDK. – Yujian Yao - MSFT Sep 07 '22 at 07:37
  • @YujianYao-MSFT: It is Win11 SDK, check https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/. – macroland Sep 07 '22 at 08:09

1 Answers1

0

There were a few things needed attention:

  1. Discontinued use of wxSQLite (the library was not maintained for over a decade),
  2. The main frame was a singleton data structure, not anymore, and not deriving from wxMDIFrame anymore.
  3. All unnecessary (a chain of them) #include removed.
  4. Inclusion of <boost/json.hpp> in a few files were removed and now using #include <boost/json/src.hpp> only in one .cpp file. However, the project still uses inclusion of <boost/json/value.hpp> in multiple .h files.
  5. All uninitialized pointer variables and others were initialized.

#1 and #4 were especially pointed by the debugger. It has now been more than a few days and haven't had the problem since then.

macroland
  • 973
  • 9
  • 27