C++ Transition Guide for 4.18

Dear Community,

Cheers and fireworks for 4.18! Yay!

Here is a thread where you can post your research & solutions as you are upgrading to 4.18.

Questions are welcome here about C++, as well as any other editor-related aspects of 4.18 that you think might be common issues.

Have fun upgrading!

:heart:

Rama

Can’t Make VS Files For Your Project?

The New Target.cs

Are you finding you can’t generate VS files for your project?

Beginning with 4.18 you must use the new target.cs setup

old:



public class PMeleeWeaponTarget : TargetRules
{
    public PMeleeWeaponTarget(TargetInfo Target)
    {
        Type = TargetType.Game;
    }

    public override void SetupBinaries(
        TargetInfo Target,
        ref List<UEBuildBinaryConfiguration> OutBuildBinaryConfigurations,
        ref List<string> OutExtraModuleNames
        )
    {
        OutExtraModuleNames.AddRange( new string] { "PMeleeWeapon" } );
    }
}


New:



public class PMeleeWeaponTarget : TargetRules
{
    public PMeleeWeaponTarget(TargetInfo Target)
        : base(Target)
    {
        Type = TargetType.Game;
        ExtraModuleNames.Add("PMeleeWeapon");
    }
}


Editor Old



public class PMeleeWeaponEditorTarget : TargetRules
{
    public PMeleeWeaponEditorTarget(TargetInfo Target)
    {
        Type = TargetType.Editor;
    }

    //
    // TargetRules interface.
    //

    public override void SetupBinaries(
        TargetInfo Target,
        ref List<UEBuildBinaryConfiguration> OutBuildBinaryConfigurations,
        ref List<string> OutExtraModuleNames
        )
    {
        OutExtraModuleNames.AddRange( new string] { "PMeleeWeapon" } );
    }
}



Editor New



public class PMeleeWeaponEditorTarget : TargetRules
{
    public PMeleeWeaponEditorTarget(TargetInfo Target)
        : base(Target)
    {
        Type = TargetType.Editor;
        ExtraModuleNames.Add("PMeleeWeapon");
    }
}


:heart:

Rama

The HMD device location has changed - but it’s a pretty simple fix up:
Previously if you did:


EHMDDeviceType::Type  device = GEngine->HMDDevice.Get()

You now do:


EHMDDeviceType::Type  device = GEngine->XRSystem->GetHMDDevice()

and #include “IXRTrackingSystem.h”

And it should all work as before.

Got this one:

And this:

Both was moved to a public folder:



#include "IImageWrapper.h"
#include "IImageWrapperModule.h"


Hi guys,

Anyone else getting compile errors on a vanilla github 4.18 source compile? I"m getting these errors and seem to be in the engine side:

GitEngines\UnrealEngine_4.18.0\Engine\Source\Programs\Mac\ShaderCacheTool\Private\ShaderCacheTool.cpp(66): error C2039: ‘MergeShaderCacheFiles’: is not a member of ‘FShaderCache’

… and…

GitEngines\UnrealEngine_4.18.0\Engine\Source\Programs\BuildPatchTool\Private\ToolModes\AutomationMode.cpp(12): fatal error C1083: Cannot open include file: ‘Interfaces/IAutomationWorkerModule.h’: No such file or directory

How do i properly relink the Destruction Apex Class since they moved it to be a plugin? https://i.gyazo.com/3d691d86ff09b038640c880a12836ee9.png

Are the DPI related functions (e.g. FGenericPlatformMisc::ConvertInchesToPixels) gone in 4.18? Is there a new way for calculating DPI? Thank you.

One of the [FONT=courier new]FTimespan() constructors changed signature from


FTimespan(int32 Days, int32 Hours, int32 Minutes, int32 Seconds, int32 Milliseconds, int32 Microseconds = 0)

to


FTimespan(int32 Days, int32 Hours, int32 Minutes, int32 Seconds, int32 FractionNano)

The easiest way to fix this is use one of the built in static functions (In my case, I used [FONT=courier new]FTimespan::FromSeconds(DeltaTime) )

[FONT=courier new]FBodyInstance functions [FONT=courier new]SetAngularVelocity() and [FONT=courier new]GetUnrealWorldAngularVelocity() are now deprecated
To fix, use their [FONT=courier new]SetAngularVelocityInRadians() and [FONT=courier new]GetUnrealWorldAngularVelocityInRadians() variants instead. Don’t forget to call [FONT=courier new]FMath:: DegreesToRadians() where needed!

Add to your .uproject or your .uplugin:



"Plugins" :
    
        {
            "Name": "ApexDestruction",
            "Enabled": true
        } 
    ]    


:heart:

Rama

Hi Devero!!!

Did this ever get resolved?

:slight_smile:

Rama

Remove the ShaderCacheTool project from your solution.

For ‘Interfaces/IAutomationWorkerModule.h’ remove the ‘Interfaces/’ portion.

I noticed that the module containing FGamepadKeyNames has been changed from Core to ApplicationCore.



struct **CORE_API** FGamepadKeyNames
{
    typedef FName Type;
...


struct **APPLICATIONCORE_API **FGamepadKeyNames
{
    typedef FName Type;
...



Since updating to 4.18, I am seeing this wierd non-fatal crash in the log my dedicated server and client on linux and windows:
(Important bits in underlined bold)


[2017.10.31-21.55.14:751]  0]LogPakFile: New pak file ../../../ProjectName/Content/Paks/ProjectName-WindowsNoEditor.pak added to pak precacher.
[2017.10.31-21.55.15:023]  0]LogStats: FPlatformStackWalk::StackWalkAndDump -  0.164 s
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error: === Handled ensure: ===
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error:
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error: Ensure condition failed: Lhs.Array.Num() == Lhs.InitialNum [File:c:\users\altrue\documents\unrealengine\engine\source\runtime\core\public\Containers/SparseArray.h] [Line: 781]
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error: **Container has changed during ranged-for iteration!**
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error: Stack:
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error: [Callstack] 0x0000000040271766 ProjectName.exe!FWindowsPlatformStackWalk::StackWalkAndDump() [c:\users\altrue\documents\unrealengine\engine\source\runtime\core\private\windows\windowsplatformstackwalk.cpp:200]
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error: [Callstack] 0x00000000400106C1 ProjectName.exe!FDebug::EnsureFailed() [c:\users\altrue\documents\unrealengine\engine\source\runtime\core\private\misc\assertionmacros.cpp:299]
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error: [Callstack] 0x000000004002AA06 ProjectName.exe!FDebug::OptionallyLogFormattedEnsureMessageReturningFalse() [c:\users\altrue\documents\unrealengine\engine\source\runtime\core\private\misc\assertionmacros.cpp:425]
**[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error: [Callstack] 0x0000000042DCC415 ProjectName.exe!FPakAsyncReadFileHandle::DoProcessing() [c:\users\altrue\documents\unrealengine\engine\source\runtime\pakfile\private\iplatformfilepak.cpp:3218]**
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error: [Callstack] 0x0000000042DCED96 ProjectName.exe!TGraphTask<FAsyncIOCPUWorkTask>::ExecuteTask() [c:\users\altrue\documents\unrealengine\engine\source\runtime\core\public\async	askgraphinterfaces.h:787]
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error: [Callstack] 0x000000003FEE5D15 ProjectName.exe!FTaskThreadAnyThread::ProcessTasks() [c:\users\altrue\documents\unrealengine\engine\source\runtime\core\private\async	askgraph.cpp:910]
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error: [Callstack] 0x000000003FEE6F8D ProjectName.exe!FTaskThreadAnyThread::ProcessTasksUntilQuit() [c:\users\altrue\documents\unrealengine\engine\source\runtime\core\private\async	askgraph.cpp:786]
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error: [Callstack] 0x000000003FEF5455 ProjectName.exe!FTaskThreadBase::Run() [c:\users\altrue\documents\unrealengine\engine\source\runtime\core\private\async	askgraph.cpp:502]
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error: [Callstack] 0x000000004026F41C ProjectName.exe!FRunnableThreadWin::Run() [c:\users\altrue\documents\unrealengine\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:76]
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error: [Callstack] 0x000000004025FF63 ProjectName.exe!FRunnableThreadWin::GuardedRun() [c:\users\altrue\documents\unrealengine\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:33]
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error: [Callstack] 0x00000000771959CD kernel32.dll!UnknownFunction ]
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error: [Callstack] 0x00000000773CA561 ntdll.dll!UnknownFunction ]
[2017.10.31-21.55.15:023]  0]LogOutputDevice: Error:

The game still runs but it’s quite ugly to systematically have a stacktrace at the beginning of your logs. Besides, it’s just broken code waiting to happen…
Any ideas?

Somewhere in your code you are modifying an array while iterating through it which may cause pointer invalidation depending on the way you’re doing it:

Yes, though it happens at the line 3218 of some pak processing code, which is in the engine code itself and not in my code.

Besides, both assertions containing this “**Container has changed during ranged-for iteration!”**text haven’t been modified between 4.17 and 4.18, leading me to believe that even if by some miracle the stacktrace was completely off, and my code was at fault, I would have seen this message in the 4.17 builds.

This seems a bit big for an engine bug though, I mean surely that kind of thing in the logs wouldn’t have passed QA. So I’m guessing this is a 4.17 -> 4.18 transition thing, hence my posting here. Is there any modification to do regarding the way we handle paks or something?

seems like in 4.18 you have to specify starting map, something like this:

“C:\Program Files\Epic Games\UE_4.18\Engine\Binaries\Win64\UE4Editor.exe” “C:\UnrealProjects\Testing\Testing.uproject” /Game/ThirdPersonCPP/Maps/ThirdPersonExampleMap -server -log

It’s working! Thx man, you’re the best!

Hi,

My commandlet plugin crashes after upgrading from 4.17 to 4.18. It crashes inside UE after calling UPackage::SavePackage:

UPackage::SavePackage(AssetPackage, NULL, RF_Standalone, *PackageFileName, GError, nullptr, false, true, SAVE_NoError)

Where,

  • AssetPackage is the pointer to an UPackage returned by FindPackage.
  • PackageFileName is the string returned by FPackageName::LongPackageNameToFilename.

The error I get is:

LogWindows: Error: Fatal error: [File:D:\Build++UE4+Release-4.18+Compile\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 278]
LogWindows: Error: Illegal call to StaticFindObject() while serializing object data!

Do you know what could have changed to cause the crash?

Thanks

Yes! I’m getting both of those! Did you manage to fix it?

This is the full call stack:

LogWindows: Error: === Critical error: ===
LogWindows: Error:
LogWindows: Error: Fatal error: [File:D:\Build++UE4+Release-4.18+Compile\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 278]
LogWindows: Error: Illegal call to StaticFindObject() while serializing object data!
LogWindows: Error:
LogWindows: Error:
LogWindows: Error: [Callstack] 0x00000000FD8AA06D KERNELBASE.dll!UnknownFunction ]
LogWindows: Error: [Callstack] 0x00000000F38476D4 UE4Editor-ApplicationCore.dll!FWindowsErrorOutputDevice::Serialize() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\applicationcore\private\windows\windowserroroutputdevice.cpp:65]
LogWindows: Error: [Callstack] 0x00000000DA8A2E0B UE4Editor-Core.dll!FOutputDevice::Logf__VA() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\core\private\misc\outputdevice.cpp:70]
LogWindows: Error: [Callstack] 0x00000000DA8347D9 UE4Editor-Core.dll!FDebug::AssertFailed() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\core\private\misc\assertionmacros.cpp:414]
LogWindows: Error: [Callstack] 0x00000000DA3E1CFC UE4Editor-CoreUObject.dll!StaticFindObject() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:281]
LogWindows: Error: [Callstack] 0x00000000D872A448 UE4Editor-Engine.dll!UStaticMesh::GetAssetRegistryTags() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\staticmesh.cpp:1995]
LogWindows: Error: [Callstack] 0x00000000DA37A352 UE4Editor-CoreUObject.dll!UPackage::SaveAssetRegistryData() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\coreuobject\private\uobject\savepackage.cpp:5635]
LogWindows: Error: [Callstack] 0x00000000DA373D17 UE4Editor-CoreUObject.dll!UPackage::Save() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\coreuobject\private\uobject\savepackage.cpp:4616]
LogWindows: Error: [Callstack] 0x00000000DA37A632 UE4Editor-CoreUObject.dll!UPackage::SavePackage() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\coreuobject\private\uobject\savepackage.cpp:5480]
LogWindows: Error: [Callstack] 0x00000000BF0313E9 UE4Editor-CommandletPlugin.dll!UApplyMaterialsCommandlet::Main() [c: emp\commandletplugin\hostproject\plugins\commandletplugin\source\commandletplugin\private\commandlets\applymaterialscommandlet.cpp:250]
LogWindows: Error: [Callstack] 0x000000003FF3D25F UE4Editor-Cmd.exe!FEngineLoop::PreInit() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:2167]
LogWindows: Error: [Callstack] 0x000000003FF3525A UE4Editor-Cmd.exe!GuardedMain() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\launch\private\launch.cpp:127]
LogWindows: Error: [Callstack] 0x000000003FF354AA UE4Editor-Cmd.exe!GuardedMainWrapper() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:134]
LogWindows: Error: [Callstack] 0x000000003FF42379 UE4Editor-Cmd.exe!WinMain() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:210]
LogWindows: Error: [Callstack] 0x000000003FF43193 UE4Editor-Cmd.exe!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253]
LogWindows: Error: [Callstack] 0x00000000779759CD kernel32.dll!UnknownFunction ]
LogWindows: Error: [Callstack] 0x0000000077BAA561 ntdll.dll!UnknownFunction ]
ogWindows: Error: [Callstack] 0x0000000077BAA561 ntdll.dll!UnknownFunction ]