Why is the InvocationList of Delegate empty when the program has been running for a while?

websoecket created in AsyncThreadTask.

void AsyncThreadTask::DoWork() {
	while(1)
	{
		if (!IsInGameThread() && !_USocket)
		{
			//
			_USocket = UUSocketManager::CreateWebSocket(_UFun->WorldContextObject->GetWorld());
			if (_USocket && _UFun)
			{
				// on connected
				_USocket->OnConnected.AddDynamic(_UFun, &UThreadFun::Connected);
				// on closed
				_USocket->OnClosed.AddDynamic(_UFun, &UThreadFun::Closed);
				// on connection error
				_USocket->OnConnectionError.AddDynamic(_UFun, &UThreadFun::ConnectionError);
				// on text message
				_USocket->OnTextMessage.AddDynamic(_UFun, &UThreadFun::TextMessage);
				// on bytes message
				_USocket->OnByteMessage.AddDynamic(_UFun, &UThreadFun::ByteMessage);
				// on retry
				_USocket->OnConnectionRetry.AddDynamic(_UFun, &UThreadFun::Retry);
				// open connection
				_USocket->Open(_UFun->SocketOptions);
			}
			//
			AsyncTask(ENamedThreads::GameThread, [=]()
				{

				});
		}
	}
}
UCLASS(Blueprintable, BlueprintType)
class FRAMEVIDEOWEBTHREADSOCKET_API UThreadFun : public UObject
{
	GENERATED_BODY()
public:
	UFUNCTION()
	void Failed(ESocketManagerError Reason = ESocketManagerError::None, FString Error = "");
	UFUNCTION()
	void Connected();
	UFUNCTION()
	void Closed(const int32& Code, const FString& Reason, bool ClosedByPeer);
	UFUNCTION()
	void ConnectionError(const FString& Reason);
	UFUNCTION()
	void TextMessage(const FString& Message);
	UFUNCTION()
	void ByteMessage(const TArray<uint8>& Message);
	UFUNCTION()
	void Retry(const int32& RetryCount);
protected:
	FVideoFrame parseVideoFrame(const FString& msg);
public:
	FSocketManagerOptions  SocketOptions;
	const UObject* WorldContextObject = nullptr;
protected:
	UJsonDataParse  DataParse;

};
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnConnectedDelegate);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnClosedDelegate, const int32&, Code, const FString&, Reason, bool, ClosedByPeer);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnConnectionErrorDelegate, const FString&, ErrorReason);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnTextMessageDelegate, const FString&, Message);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnMessageSentDelegate, const FString&, Message);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnByteMessageDelegate, const TArray<uint8>&, Message);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnRetryDelegate, const int32&, RetryCount);
/**
 * 
 */
UCLASS()
class FRAMEVIDEOWEBTHREADSOCKET_API UUSocketManager : public UObject
{
	GENERATED_BODY()
public:
	UPROPERTY(BlueprintAssignable, Category = "SocketManagerEvent")
		FOnConnectedDelegate OnConnected;
	UPROPERTY(BlueprintAssignable, Category = "SocketManager|Event")
		FOnClosedDelegate OnClosed;
	UPROPERTY(BlueprintAssignable, Category = "SocketManager|Event")
		FOnConnectionErrorDelegate OnConnectionError;
	UPROPERTY(BlueprintAssignable, Category = "SocketManager|Event")
		FOnTextMessageDelegate OnTextMessage;
	UPROPERTY(BlueprintAssignable, Category = "SocketManager|Event")
		FOnByteMessageDelegate OnByteMessage;
	UPROPERTY(BlueprintAssignable, Category = "SocketManager|Event")
		FOnMessageSentDelegate OnMessageSent;
	UPROPERTY(BlueprintAssignable, Category = "SocketManager|Event")
		FOnRetryDelegate OnConnectionRetry;
private:
	FSocketManagerOptions Options;
	TSharedPtr<IWebSocket> Socket;
	TArray<uint8> Buffer;
	FTimerHandle ReconnectHandle;
	int32 ReconnectAmount = 0;
	UWorld* WorldContextObject = nullptr;
public:
	~UUSocketManager();
	//UFUNCTION(BlueprintPure, Category = "SocketManager", meta = (WorldContext = "WorldContext"))
	//	static UUSocketManager* CreateWebSocket(const UObject* WorldContext);
	UFUNCTION(BlueprintPure, Category = "SocketManager")
		static UUSocketManager* CreateWebSocket(UWorld* WorldContextObject);
	UFUNCTION(BlueprintPure, Category = "SocketManager")
		bool IsConnected();
	UFUNCTION(BlueprintCallable, Category = "SocketManager")
		bool Open(const FSocketManagerOptions& Ops);
	UFUNCTION(BlueprintCallable, Category = "SocketManager")
		bool Close(int32 Code = 1000, const FString& Reason = "");
	UFUNCTION(BlueprintCallable, Category = "SocketManager")
		bool SendText(const FString& Data);
	UFUNCTION(BlueprintCallable, Category = "SocketManager")
		bool SendBytes(const TArray<uint8>& Data, bool IsBinary = false);
};

Hi,
I’m having the same issue. Did you find the source of the trouble?

Something I’ve done in the past to figure out issues like this is putting a breakpoint when a value changes
So in this case I would put a breakpoint when binding the function to the delegate, and then expand all the way to find the ArrayNum field of the invocation list (I think it’s under Raw View), and right click → Break when value changes (that’s for Visual Studio, not sure about other IDEs)
Then whenever another function is bound or one is removed from the delegate’s invocation list VS will break allowing you to see the call stack and figure out what caused the removal

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.