I use a background loading technique for my game, following tutorial.
However, I've encountered a problem. When using background loading, there's a chance of memory corruption, which can cause unexpected crashes that are difficult to track down.
https://i.gyazo.com/ab05865d7a58d085687a...65266.png, the mag (pointer) is not null, but some values of its class are unabled to read, mag is created inside background loading process
I suspect the issue arises because the thread handling the background loading is terminated before it completes its task. Even though I use a boolean flag at the end of the loading code to ensure all operations are executed, the problem persists.
My background loading process includes dynamically generated objects (such as characters and props) in addition to pre-placed objects created using the editor. Most of the time, background loading works fine, but occasionally it crashes.
Disabling background loading and using normal loading (which lacks a loading progress bar and temporarily freezes the game) eliminates the crashes.
Is there an effective method to ensure all background loading tasks are completed?