I have a struct* that I’m trying to pass to a TSharedPtr. This is because I’m trying to send some data on to be computed on another thread, via FRunnable, and using a ‘normal’ pointer results in a crash.
I’m confused how to cast my ‘normal’ pointer to a TSharedPtr.
with NearCont being an FRunnableContainer* (non-USTRUCT) causes a crash.
Furthermore, it seems to match the template for TSharedPtr, I get no red squiggly in VS, and I check (multiple times) to make sure that the pointer is non-null.
Thanks again RxDesu for the help, but unfortunately this still causes a crash for the same reason.
I now imagine this must be the result of my general workflow with the Runnable.
I have an Actor in the scene which is in charge of the runnable. In contains a list of AI characters in the scene who have needs to be fulfilled - Hunger, Thirst, Sleep, etc. So, every tick, this ‘manager’ actor chooses a character from its list, gets it’s ‘needs’ struct, and passes it on to the runnable. The runnable is created on BeginPlay, and while running will process the decay for those needs. It also checks to make sure the pointer IsValid().
There are several possible errors that could be made.
Provide some code samples for your pointer management. It will be helpful. (struct field declation in AICharacter, FRunnable method call and maybe that method implementation details)
1.) You reference your FRunnable via a TSharedPtr - i.e [FONT=courier new]TSharedPtr<FMyRunnable> MyRunnable. I have it set up as [FONT=courier new]FMyRunnable* MyRunnable.
2.) You run the thread in a function called “Start”. Mine begins in the constructor.
3.) Your Thread is a [FONT=courier new]TSharedPtr as well. Mine is not.
4.) I have no Init() function, nor a Stop() function. Even if that isn’t causing the crash, that can obviously become a problem.
I’m going to check all of those and see if maybe one or more is responsible for the crash, but if you see any that look particularly evil let me know.
Here is the code pertinent to the error, and then some: Clone - Google Drive
The actual line that causes the crash is Line 23 in Runnable Manager.