Hi there,
first of all, excuse any mistake in posting since its my first post.
I am working on an implementation which allows me to send any data (and also size) from server to client. For that purpose i defined an interface in C++, in which i define the fundamentals like receiving and providing data. The whole networking is done in the class AMimiNetLoader.
My interface:
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "MimiNetLoadable.generated.h"
class AMimiNetLoader;
UINTERFACE(MinimalAPI)
class UMimiNetLoadable : public UInterface
{
GENERATED_BODY()
};
class MIMITD_API IMimiNetLoadable
{
GENERATED_BODY()
public:
virtual void NetLoaderAvailable(AMimiNetLoader* RefNetLoader) = 0;
virtual void NetLoaderDataAvailable(const uint8* Data,
const uint32 Size) = 0;
virtual void NetLoaderDataRequested(uint8* Data, const uint32 Size,
uint32* BytesWritten) = 0;
virtual uint32 NetLoaderAcceptedPacketTypes() const = 0;
};
My class implementing the interface:
class MIMITD_API AMimiTileMap : public APaperTileMapActor, public IMimiNetLoadable
and the CPP side of that class (of course i implemented all other pure virtual methods aswell):
void AMimiTileMap::NetLoaderAvailable(AMimiNetLoader* RefNetLoader)
{
// request tilemap if you are a client
if(GetLocalRole() == ROLE_AutonomousProxy)
RefNetLoader->RequestData(this);
}
Now: MimiNetLoader is created in GameMode::PostLogin(…). Its ownership is then set to the PlayerController which conntected and in MimiNetLoader::BeginPlay() it gets all Actors implementing my interface. I then proceed to call IMimiNetLoadable::NetLoaderAvailable(this), which causes an accessviolation.
void AMimiNetLoader::BeginPlay()
{
Super::BeginPlay();
UGameplayStatics::GetAllActorsWithInterface(GetWorld(),
UMimiNetLoadable::StaticClass(), NetLoadables);
for (int32 i = 0; i < NetLoadables.Num(); ++i)
{
// NetLoadables is a member of AMimiNetLoader of type TArray<AActor*>
IMimiNetLoadable* Loadable
= reinterpret_cast<IMimiNetLoadable*>(NetLoadables*);
// with the debugger i could determine that Loadable was indeed my TileMap implementation
Loadable->NetLoaderAvailable(this); // this line causes an access violation, trying to access 0x0...0004
}
}
Now, i’m not sure if it is caused by me doing stuff in PostLogin or by me doing something wrong with the interface. It seems the error occurs within unreals dlls and thus i can’t really determine whats going wrong.
Any ideas?