Merge remote-tracking branch 'origin/master' into 1.7

This commit is contained in:
Wojtek Figat
2023-08-10 18:34:27 +02:00
17 changed files with 45 additions and 34 deletions

View File

@@ -903,11 +903,25 @@ namespace FlaxEngine.Interop
AssemblyLocations.Remove(assembly.FullName);
// Clear all caches which might hold references to closing assembly
// Unload native library handles associated for this assembly
string nativeLibraryName = assemblyOwnedNativeLibraries.GetValueOrDefault(assembly);
if (nativeLibraryName != null && loadedNativeLibraries.TryGetValue(nativeLibraryName, out IntPtr nativeLibrary))
{
NativeLibrary.Free(nativeLibrary);
loadedNativeLibraries.Remove(nativeLibraryName);
}
if (nativeLibraryName != null)
nativeLibraryPaths.Remove(nativeLibraryName);
}
[UnmanagedCallersOnly]
internal static void ReloadScriptingAssemblyLoadContext()
{
#if FLAX_EDITOR
// Clear all caches which might hold references to assemblies in collectible ALC
typeCache.Clear();
// Release all references in collectible ALC
#if FLAX_EDITOR
cachedDelegatesCollectible.Clear();
foreach (var pair in typeHandleCacheCollectible)
pair.Value.Free();
@@ -918,23 +932,13 @@ namespace FlaxEngine.Interop
foreach (var handle in fieldHandleCacheCollectible)
handle.Free();
fieldHandleCacheCollectible.Clear();
#endif
_typeSizeCache.Clear();
foreach (var pair in classAttributesCacheCollectible)
pair.Value.Free();
classAttributesCacheCollectible.Clear();
// Unload native library handles associated for this assembly
string nativeLibraryName = assemblyOwnedNativeLibraries.GetValueOrDefault(assembly);
if (nativeLibraryName != null && loadedNativeLibraries.TryGetValue(nativeLibraryName, out IntPtr nativeLibrary))
{
NativeLibrary.Free(nativeLibrary);
loadedNativeLibraries.Remove(nativeLibraryName);
}
if (nativeLibraryName != null)
nativeLibraryPaths.Remove(nativeLibraryName);
// Unload the ALC
bool unloading = true;
scriptingAssemblyLoadContext.Unloading += (alc) => { unloading = false; };
@@ -945,6 +949,7 @@ namespace FlaxEngine.Interop
InitScriptingAssemblyLoadContext();
DelegateHelpers.InitMethods();
#endif
}
[UnmanagedCallersOnly]

View File

@@ -3,6 +3,7 @@
#include "ParticleEmitterGraph.CPU.h"
#include "Engine/Core/Random.h"
#include "Engine/Utilities/Noise.h"
#include "Engine/Core/Types/CommonValue.h"
// ReSharper disable CppCStyleCast
// ReSharper disable CppClangTidyClangDiagnosticCastAlign

View File

@@ -6,6 +6,7 @@
#include "Engine/Serialization/FileReadStream.h"
#include "Engine/Visject/ShaderGraphUtilities.h"
#include "Engine/Engine/Globals.h"
#include "Engine/Core/Types/CommonValue.h"
/// <summary>
/// GPU particles shader source code template has special marks for generated code.

View File

@@ -8,6 +8,7 @@
#include "Engine/Particles/Types.h"
#include "Engine/Particles/ParticlesSimulation.h"
#include "Engine/Particles/ParticlesData.h"
#include "Engine/Core/Types/CommonValue.h"
class ParticleEffect;

View File

@@ -2,6 +2,7 @@
#include "ParticleEffect.h"
#include "Particles.h"
#include "Engine/Core/Types/CommonValue.h"
#include "Engine/Serialization/JsonTools.h"
#include "Engine/Serialization/Serialization.h"
#include "Engine/Level/Scene/SceneRendering.h"

View File

@@ -3,6 +3,7 @@
#pragma once
#include "Engine/Content/BinaryAsset.h"
#include "Engine/Core/Math/BoundingBox.h"
#include "Engine/Graphics/Shaders/Cache/ShaderAssetBase.h"
#include "Graph/CPU/ParticleEmitterGraph.CPU.h"
#if COMPILE_WITH_GPU_PARTICLES

View File

@@ -2,6 +2,7 @@
#include "ParticleSystem.h"
#include "ParticleEffect.h"
#include "Engine/Core/Types/CommonValue.h"
#include "Engine/Level/Level.h"
#include "Engine/Content/Factories/BinaryAssetFactory.h"
#include "Engine/Serialization/MemoryReadStream.h"

View File

@@ -6,6 +6,7 @@
#include "Particles.h"
#include "Engine/Graphics/GPUBuffer.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Core/Types/CommonValue.h"
ParticleEmitterInstance::ParticleEmitterInstance()
{

View File

@@ -2,7 +2,6 @@
#pragma once
#include "Engine/Core/Types/CommonValue.h"
#include "Engine/Visject/GraphParameter.h"
class ParticleSystemInstance;

View File

@@ -1191,11 +1191,8 @@ void* WindowsPlatform::LoadLibrary(const Char* filename)
folder = StringView::Empty;
if (folder.HasChars())
{
Char& end = ((Char*)folder.Get())[folder.Length()];
const Char c = end;
end = 0;
SetDllDirectoryW(*folder);
end = c;
String folderNullTerminated(folder);
SetDllDirectoryW(folderNullTerminated.Get());
}
// Avoiding windows dialog boxes if missing

View File

@@ -190,8 +190,8 @@ void PostProcessingPass::Render(RenderContext& renderContext, GPUTexture* input,
PostProcessSettings& settings = renderContext.List->Settings;
bool useBloom = EnumHasAnyFlags(view.Flags, ViewFlags::Bloom) && settings.Bloom.Enabled && settings.Bloom.Intensity > 0.0f;
bool useToneMapping = EnumHasAnyFlags(view.Flags, ViewFlags::ToneMapping);
bool useCameraArtifacts = EnumHasAnyFlags(view.Flags, ViewFlags::CameraArtifacts);
bool useToneMapping = EnumHasAnyFlags(view.Flags, ViewFlags::ToneMapping) && settings.ToneMapping.Mode != ToneMappingMode::None;
bool useCameraArtifacts = EnumHasAnyFlags(view.Flags, ViewFlags::CameraArtifacts) && (settings.CameraArtifacts.VignetteIntensity > 0.0f || settings.CameraArtifacts.GrainAmount > 0.0f || settings.CameraArtifacts.ChromaticDistortion > 0.0f || settings.CameraArtifacts.ScreenFadeColor.A > 0.0f);
bool useLensFlares = EnumHasAnyFlags(view.Flags, ViewFlags::LensFlares) && settings.LensFlares.Intensity > 0.0f && useBloom;
// Ensure to have valid data and if at least one effect should be applied

View File

@@ -47,7 +47,7 @@ public:
#if USE_EDITOR
// Called by Scripting in a middle of hot-reload (after unloading modules but before loading them again).
static void OnMidHotReload();
static void ReloadScriptingAssemblyLoadContext();
#endif
public:

View File

@@ -160,6 +160,7 @@ DECLARE_ENUM_OPERATORS(MTypeAttributes);
DECLARE_ENUM_OPERATORS(MMethodAttributes);
DECLARE_ENUM_OPERATORS(MFieldAttributes);
// Multiple AppDomains are superseded by AssemblyLoadContext in .NET
extern MDomain* MRootDomain;
extern MDomain* MActiveDomain;
extern Array<MDomain*, FixedAllocation<4>> MDomains;
@@ -301,11 +302,14 @@ void MCore::UnloadEngine()
#if USE_EDITOR
void MCore::OnMidHotReload()
void MCore::ReloadScriptingAssemblyLoadContext()
{
// Clear any cached class attributes (see https://github.com/FlaxEngine/FlaxEngine/issues/1108)
for (auto e : CachedClassHandles)
e.Value->_attributes.Clear();
static void* ReloadScriptingAssemblyLoadContextPtr = GetStaticMethodPointer(TEXT("ReloadScriptingAssemblyLoadContext"));
CallStaticMethod<void>(ReloadScriptingAssemblyLoadContextPtr);
}
#endif
@@ -723,16 +727,12 @@ bool MAssembly::LoadImage(const String& assemblyPath, const StringView& nativePa
bool MAssembly::UnloadImage(bool isReloading)
{
if (_handle)
if (_handle && isReloading)
{
// TODO: closing assembly on reload only is copy-paste from mono, do we need do this on .NET too?
if (isReloading)
{
LOG(Info, "Unloading managed assembly \'{0}\' (is reloading)", String(_name));
LOG(Info, "Unloading managed assembly \'{0}\' (is reloading)", String(_name));
static void* CloseAssemblyPtr = GetStaticMethodPointer(TEXT("CloseAssembly"));
CallStaticMethod<void, const void*>(CloseAssemblyPtr, _handle);
}
static void* CloseAssemblyPtr = GetStaticMethodPointer(TEXT("CloseAssembly"));
CallStaticMethod<void, const void*>(CloseAssemblyPtr, _handle);
CachedAssemblyHandles.Remove(_handle);
_handle = nullptr;

View File

@@ -716,7 +716,7 @@ void MCore::UnloadEngine()
#if USE_EDITOR
void MCore::OnMidHotReload()
void MCore::ReloadScriptingAssemblyLoadContext()
{
}

View File

@@ -61,7 +61,7 @@ void MCore::UnloadEngine()
#if USE_EDITOR
void MCore::OnMidHotReload()
void MCore::ReloadScriptingAssemblyLoadContext()
{
}

View File

@@ -706,7 +706,9 @@ void Scripting::Reload(bool canTriggerSceneReload)
modules.Clear();
_nonNativeModules.ClearDelete();
_hasGameModulesLoaded = false;
MCore::OnMidHotReload();
// Release and create a new assembly load context for user assemblies
MCore::ReloadScriptingAssemblyLoadContext();
// Give GC a try to cleanup old user objects and the other mess
MCore::GC::Collect();

View File

@@ -36,6 +36,7 @@
#include <math.h>
#include <stdint.h>
#include <limits>
#include <initializer_list>
#include "core.h"