x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Crash when spawning actors in 20 player net game

Getting this crash when spawning actors in a 20 player network game test. This code runs many times per mininute in the game, so does not fail every time, and has never crashed when testing networked in the editor. Due to the way the build is being made, it's hard to debug any of these lines that are in the engine code, only 2 of the lines i the below stack are in the code written for the game.

 TSet<class UObjectBase *,struct DefaultKeyFuncs<class UObjectBase *,0>,class FDefaultSetAllocator>::FindId(class UObjectBase *)    C++
 TSet<class UObjectBase *,struct DefaultKeyFuncs<class UObjectBase *,0>,class FDefaultSetAllocator>::Emplace<class UObjectBase * const &>(class UObjectBase * const &,bool *)    C++
 HashObject(class UObjectBase *)    C++
 UObjectBase::AddObject(class FName,enum EInternalObjectFlags)    C++
 StaticAllocateObject(class UClass *,class UObject *,class FName,enum EObjectFlags,enum EInternalObjectFlags,bool,bool *)    C++
 StaticConstructObject_Internal(class UClass *,class UObject *,class FName,enum EObjectFlags,enum EInternalObjectFlags,class UObject *,bool,struct FObjectInstancingGraph *,bool)    C++
 UWorld::SpawnActor(class UClass *,struct FTransform const *,struct FActorSpawnParameters const &)    C++
 ARangedWeapon::BeginPlay() Line 52    C++
 ARangedWeaponProjectile::BeginPlay() Line 34    C++
 AActor::DispatchBeginPlay(void)    C++
 AActor::PostNetInit(void)    C++
 UActorChannel::ProcessBunch(class FInBunch &)    C++
 UActorChannel::ReceivedBunch(class FInBunch &)    C++
 UChannel::ReceivedNextBunch(class FInBunch &,bool &)    C++
 UChannel::ReceivedRawBunch(class FInBunch &,bool &)    C++
 UNetConnection::ReceivedPacket(struct FBitReader &)    C++
 UNetConnection::ReceivedRawPacket(void *,int)    C++
 UIpNetDriver::TickDispatch(float)    C++
 TBaseUObjectMethodDelegateInstance<0,class UNetDriver,void >::ExecuteIfSafe(float)    C++
 TBaseMulticastDelegate<void,float>::Broadcast(float)    C++
 UWorld::Tick(enum ELevelTick,float)    C++
 UGameEngine::Tick(float,bool)    C++
 FEngineLoop::Tick(void)    C++
 GuardedMain(wchar_t const *,struct HINSTANCE__ *,struct HINSTANCE__ *,int)    C++
 GuardedMainWrapper(wchar_t const *,struct HINSTANCE__ *,struct HINSTANCE__ *,int)    C++
 WinMain()    C++

The code in question was this....

.h

 /** the weapon sound fx to use when the weapon is fired. This is the blueprint that responds to weapon events to play the sounds. */
 UPROPERTY( EditDefaultsOnly, Category = Sound )
 TSubclassOf<AWeaponSoundFX> WeaponSoundFX_Template;

.cpp

 void ARangedWeapon::BeginPlay()
 {
     Super::BeginPlay();
 
     if ( WeaponSoundFX_Template != nullptr && GetNetMode() != NM_DedicatedServer )
     {        
         FTransform SpawnTransform = FTransform::Identity;
         WeaponSoundFX = GetWorld()->SpawnActor<AWeaponSoundFX>(    WeaponSoundFX_Template, SpawnTransform );
     }
 }


So the only things i can see is...

GetWorld() - so this can return null? is this supposed to be checked, if so, there are places in the engine itself where this is never checked. It seems it can be null when the world is shutting down or when the object is being destroyed, but i verified from the crash dump that neither of these situations were happening.

Product Version: UE 4.22
Tags:
more ▼

asked May 21 '19 at 01:40 PM in C++ Programming

avatar image

Dave.A2
1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

The issue is WeaponSoundFX_Template and not GetWorld, you need to dereference TSubClassOf to get the UClass it may or may not have.

  void ARangedWeapon::BeginPlay()
  {
      Super::BeginPlay();
  
      if ( *WeaponSoundFX_Template != nullptr && GetNetMode() != NM_DedicatedServer )
      {        
          FTransform SpawnTransform = FTransform::Identity;
          WeaponSoundFX = GetWorld()->SpawnActor<AWeaponSoundFX>(    *WeaponSoundFX_Template, SpawnTransform );
      }
  }
more ▼

answered May 22 '19 at 02:54 PM

avatar image

ExtraLifeMatt
1.6k 34 14 48

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Thanks for the answer, but without changing any code and stepping through this code in the editor shows that the dereference is implicitly happening anyway....

 [Inline Frame] UE4Editor-.dll!TSubclassOf<AWeaponSoundFX>::operator*() Line 55    C++
 [Inline Frame] UE4Editor-.dll!TSubclassOf<AWeaponSoundFX>::operator class UClass *() Line 77    C++
 UE4Editor-.dll!ARangedWeapon::BeginPlay() Line 50    C++
 UE4Editor-Engine.dll!AActor::DispatchBeginPlay() Line 3343    C++

Which is good, as if you need to dereference this to use it and it silently compiles without any errors or warnings, that would be really bad.

more ▼

answered May 22 '19 at 03:57 PM

avatar image

Dave.A2
1

avatar image ExtraLifeMatt May 22 '19 at 04:01 PM

Right, but is that If check doing the implicit conversion? Otherwise you may be dereferencing it and passing in a nullptr as the UClass.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question