Crash when using virtual function and override
Greetings. I'm getting an unhandled exception crash when I run a function as virtual but I don't get the crash if I'm not running a function as virtual. I'm wondering if perhaps there are any quirks about UE4's virtual functions that I'm unaware of.
In my game, one of my actor classes has a TArray of USpellSpeech pointers. USpellSpeech is a base class and I'm only using child classes of USpellSpeech. In my base spell speech class, if I write my OnHit function as a standard function, the game does not crash but accesses the base function (not what I want). If I write the function as virtual, with the child classes having a virtual override of that function, the game crashes. I am trying to call the child version of the function.
The error I receive when using the virtual version of OnHit() is Unhandled Exception (UE4Editor-GameName-Win64-DebugGame.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0xFFFFFFFF.
Normally when I see this error, I assume to look for something being uninitialized, but all I've changed is whether or not the function is virtual (I can consistently go back and forth with the change and crash). Additionally, while debugging AddSpeech(), the parameter comes through as a properly constructed UImmolate and not as a base SpellSpeech, so both construction and casting seems to be working fine.Oh, and both "this"and the actor that is passed in to OnHit is also valid.
asked Apr 20 '16 at 05:06 AM in C++ Programming
Try to use UPROPERTY() for declaration of _speeches to avoid GC issues.
answered Apr 20 '16 at 07:31 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here