Fix a razer chroma crash that would happen if the modular feature was not registered correctly

#jira UE-215782
#rb dan.oconnor
#pf 66564a838a6af08dc2370ce8

[CL 33972302 by ben hoffman in ue5-main branch]
This commit is contained in:
ben hoffman
2024-05-29 09:56:06 -04:00
parent 2b4284bc44
commit 7843170a85
4 changed files with 72 additions and 15 deletions

View File

@@ -115,16 +115,19 @@ namespace UE::RazerChroma
TEXT("Forcibly reinitalizes the Razer Chroma Editor API (calls Uninit, and then Init)."),
FConsoleCommandDelegate::CreateLambda([]()
{
FRazerChromaDeviceModule::Get().ForceReinitalize();
if (FRazerChromaDeviceModule* Module = FRazerChromaDeviceModule::Get())
{
Module->ForceReinitalize();
}
})
);
#endif //#if RAZER_CHROMA_SUPPORT
}
FRazerChromaDeviceModule& FRazerChromaDeviceModule::Get()
FRazerChromaDeviceModule* FRazerChromaDeviceModule::Get()
{
return IModularFeatures::Get().GetModularFeature<FRazerChromaDeviceModule>(UE::RazerChroma::FeatureName);
return (FRazerChromaDeviceModule*)IModularFeatures::Get().GetModularFeatureImplementation(UE::RazerChroma::FeatureName, 0);
}
FName FRazerChromaDeviceModule::GetModularFeatureName()
@@ -303,7 +306,13 @@ void FRazerChromaDeviceModule::ForceReinitalize()
bool FRazerChromaDeviceModule::IsChromaRuntimeAvailable()
{
return FRazerChromaDeviceModule::Get().IsChromaAvailable();
FRazerChromaDeviceModule* Module = FRazerChromaDeviceModule::Get();
if (!Module)
{
return false;
}
return Module->IsChromaAvailable();
}
const int32 FRazerChromaDeviceModule::FindOrLoadAnimationData(const URazerChromaAnimationAsset* AnimAsset)
@@ -354,4 +363,4 @@ const int32 FRazerChromaDeviceModule::FindOrLoadAnimationData(const FString& Ani
#endif // #if RAZER_CHROMA_SUPPORT
IMPLEMENT_MODULE(FRazerChromaDeviceModule, RazerChromaDevices)
IMPLEMENT_MODULE(FRazerChromaDeviceModule, RazerChromaDevices)

View File

@@ -12,7 +12,7 @@ class URazerChromaAnimationAsset;
class RAZERCHROMADEVICES_API FRazerChromaDeviceModule : public IInputDeviceModule
{
public:
static FRazerChromaDeviceModule& Get();
static FRazerChromaDeviceModule* Get();
static FName GetModularFeatureName();

View File

@@ -42,7 +42,13 @@ bool URazerChromaFunctionLibrary::PlayChromaAnimation(const URazerChromaAnimatio
return false;
}
const int32 LoadedAnimId = FRazerChromaDeviceModule::Get().FindOrLoadAnimationData(AnimToPlay);
FRazerChromaDeviceModule* Module = FRazerChromaDeviceModule::Get();
if (!Module)
{
return false;
}
const int32 LoadedAnimId = Module->FindOrLoadAnimationData(AnimToPlay);
if (LoadedAnimId == INDEX_NONE)
{
UE_LOG(LogRazerChroma, Error, TEXT("[%hs] Failed to load Chroma Animation %s"), __func__, *GetNameSafe(AnimToPlay));
@@ -74,7 +80,13 @@ bool URazerChromaFunctionLibrary::IsAnimationPlaying(const URazerChromaAnimation
return false;
}
const int32 LoadedAnimId = FRazerChromaDeviceModule::Get().FindOrLoadAnimationData(Anim);
FRazerChromaDeviceModule* Module = FRazerChromaDeviceModule::Get();
if (!Module)
{
return false;
}
const int32 LoadedAnimId = Module->FindOrLoadAnimationData(Anim);
if (LoadedAnimId == INDEX_NONE)
{
UE_LOG(LogRazerChroma, Error, TEXT("[%hs] Failed to load Chroma Animation %s"), __func__, *GetNameSafe(Anim));
@@ -101,7 +113,13 @@ void URazerChromaFunctionLibrary::StopChromaAnimation(const URazerChromaAnimatio
return;
}
const int32 LoadedAnimId = FRazerChromaDeviceModule::Get().FindOrLoadAnimationData(AnimToStop);
FRazerChromaDeviceModule* Module = FRazerChromaDeviceModule::Get();
if (!Module)
{
return;
}
const int32 LoadedAnimId = Module->FindOrLoadAnimationData(AnimToStop);
if (LoadedAnimId == INDEX_NONE)
{
UE_LOG(LogRazerChroma, Error, TEXT("[%hs] Failed to load Chroma Animation %s"), __func__, *GetNameSafe(AnimToStop));
@@ -128,7 +146,13 @@ void URazerChromaFunctionLibrary::PauseChromaAnimation(const URazerChromaAnimati
return;
}
const int32 LoadedAnimId = FRazerChromaDeviceModule::Get().FindOrLoadAnimationData(AnimToPause);
FRazerChromaDeviceModule* Module = FRazerChromaDeviceModule::Get();
if (!Module)
{
return;
}
const int32 LoadedAnimId = Module->FindOrLoadAnimationData(AnimToPause);
if (LoadedAnimId == INDEX_NONE)
{
UE_LOG(LogRazerChroma, Error, TEXT("[%hs] Failed to load Chroma Animation %s"), __func__, *GetNameSafe(AnimToPause));
@@ -154,7 +178,13 @@ bool URazerChromaFunctionLibrary::IsChromaAnimationPaused(const URazerChromaAnim
return false;
}
const int32 LoadedAnimId = FRazerChromaDeviceModule::Get().FindOrLoadAnimationData(Anim);
FRazerChromaDeviceModule* Module = FRazerChromaDeviceModule::Get();
if (!Module)
{
return false;
}
const int32 LoadedAnimId = Module->FindOrLoadAnimationData(Anim);
if (LoadedAnimId == INDEX_NONE)
{
UE_LOG(LogRazerChroma, Error, TEXT("[%hs] Failed to load Chroma Animation %s"), __func__, *GetNameSafe(Anim));
@@ -180,8 +210,14 @@ void URazerChromaFunctionLibrary::ResumeChromaAnimation(const URazerChromaAnimat
UE_LOG(LogRazerChroma, Error, TEXT("[%hs] Invalid AnimToResume!"), __func__);
return;
}
FRazerChromaDeviceModule* Module = FRazerChromaDeviceModule::Get();
if (!Module)
{
return;
}
const int32 LoadedAnimId = FRazerChromaDeviceModule::Get().FindOrLoadAnimationData(AnimToResume);
const int32 LoadedAnimId = Module->FindOrLoadAnimationData(AnimToResume);
if (LoadedAnimId == INDEX_NONE)
{
UE_LOG(LogRazerChroma, Error, TEXT("[%hs] Failed to load Chroma Animation %s"), __func__, *GetNameSafe(AnimToResume));
@@ -218,8 +254,14 @@ void URazerChromaFunctionLibrary::SetIdleAnimation(const URazerChromaAnimationAs
return;
}
FRazerChromaDeviceModule* Module = FRazerChromaDeviceModule::Get();
if (!Module)
{
return;
}
// Load the animation
const int32 LoadedAnimId = FRazerChromaDeviceModule::Get().FindOrLoadAnimationData(NewIdleAnimation);
const int32 LoadedAnimId = Module->FindOrLoadAnimationData(NewIdleAnimation);
if (LoadedAnimId == INDEX_NONE)
{
@@ -345,4 +387,4 @@ FString URazerChromaFunctionLibrary::LexToString(const ERazerChromaDeviceTypes D
FString URazerChromaFunctionLibrary::Conv_RazerChromaDeviceTypesToString(const int32 DeviceTypes)
{
return URazerChromaFunctionLibrary::LexToString(static_cast<ERazerChromaDeviceTypes>(DeviceTypes));
}
}

View File

@@ -108,8 +108,14 @@ void FRazerChromaInputDevice::HandlePlayAnimationFile(const FRazerChromaPlayAnim
UE_LOG(LogRazerChroma, Error, TEXT("[%hs] There is no animation data for chroma effect %s"), __func__, *Property.AnimName);
return;
}
FRazerChromaDeviceModule* Module = FRazerChromaDeviceModule::Get();
if (!Module)
{
return;
}
const int32 LoadedAnimId = FRazerChromaDeviceModule::Get().FindOrLoadAnimationData(Property.AnimName, Property.AnimationByteBuffer);
const int32 LoadedAnimId = Module->FindOrLoadAnimationData(Property.AnimName, Property.AnimationByteBuffer);
if (LoadedAnimId == -1)
{