Freeze deserializing NotifyPropertyChanged aspect - postsharp

We use Postsharp to automate the INotifyPropertyChanged implementation in our WPF application. It works great but at startup, we have a UI freeze deserializing aspects.
See visual studio call stack
The duration of the freeze is variable. It varies from 3 seconds to 25 seconds.
If I remove the NotifyPropertyChanged aspect on the base class of our viewmodels, the application starts instantly without freeze.
I can't control the deserialization moment (deserialization starts when the first occurence of an aspect is met) and it seems I can't change the serialization mecanism of the NotifyPropertyChanged aspect provided by Postsharp.
It is problematic for us because it locks the login page. Our version of Postharp is 5.0.45.0.
Is there a workaround to avoid this kind of freeze ? Does anyone know a solution to that ?
Thanks in advance.

Related

Unity Glitching when I run the Game

I made a Model of the solar system and when I run the program this happens:
I am not sure what is causing this so if you have any idea Pls Reply.
The Scene load is being triggered multiple times:
Check if you have any code that you're using to load the scene (In Update, perhaps?) if youre using it in update, check if you're using GetKey instead of GetKeyDown (GetKey will remain true as long as you keep it pressed)
The information provided here is too little and we can only speculate at this point. please post code, more images and a better description of the problem. How did you reproduce this issue?

Detect gameobject removal from user action

I'm working on a system that automatically generate and release scriptable object that represent uniqueness for gameobject with a given component attach.
The generation process seems to be working really fine, but I'm facing problem when I want to release the scriptable object.
The given script is tagged "ExecuteInEditMode" and is implementating OnDestroy method to advertise a manager that his scriptable object should be deleted.
The problem is that OnDestroy is called in 4 situation from what i can tell :
Click on play
Switching scene
Manual removal (the only one I want to work with)
On editor shutdown
I've been able to avoid the 2 first on with this :
if (Application.isPlaying == false && Math.Abs(Time.timeSinceLevelLoad) > 0.00001f)
But I don't find any good solution for "On editor shutdown" I've seen that EditorApplication.quitting can be use for that case, but documentation warn that this event is not called when unity crash or is forced to quit, and I don't want to lose all my scriptable object if the editor crash.
I'm looking for a robust solution to avoid this problem if someone can help me please.
Thanks, have a nice day
Just handle the application quitting event.
this event is not called when unity crash or is forced to quit, and I don't want to lose all my scriptable object if the editor crash.
When unity crashes, so will your program, so it won't work any ways. Just make sure that under normal operating procedure (so a normal shutdown) you save your modifications.
In Unity3D if you edit your scene and you don't save, if the editor crashes you lose all your changes. The same will happen for what you're building here. In order to mitigate this risk (since prevention is reasonably difficult if not impossible) you can opt to save every minute, always save each change to a temporary location, or save for example every play.
For example i added a script to my project that autosaves the scene(s) whenever i press play, so when editing the scene i press play now and then to test, and it all gets autosaved.

Unreal Engine: accessing/saving in-game images to disk without blocking game thread

I am working on an Unreal based open-source UAV simulation (Microsoft AirSim) where I am trying to capture and save images from a camera that's attached to the drone. The image underneath gives an idea of how the game looks like. The rightmost view on the bottom is the actual view from the camera, the other two are just processed versions of the same image.
Right now the way it's set up in this way: There's a camera asset, which is read through the code as a capture component. The three views in the screenshot are linked to this capture component. The views are streamed without any problem as the drone is flown around in-game. But when it comes to recording screenshots, the current code sets up a TextureRenderTargetResource from this capture component, and subsequently calls ReadPixels and saves that data as an image (please see below for code flow). Using ReadPixels() as it is, is blocking the game thread directly and slowing down the whole game by a lot: drops from ~120 FPS to less than 10 FPS when I start recording.
bool saveImage() {
USceneCaptureComponent2D* capture = getCaptureComponent(camera_type, true);
FTextureRenderTargetResource* RenderResource = capture->TextureTarget->GameThread_GetRenderTargetResource();
width = capture->TextureTarget->GetSurfaceWidth();
height = capture->TextureTarget->GetSurfaceHeight();
TArray<FColor> imageColor;
imageColor.AddUninitialized(width * height);
RenderResource->ReadPixels(bmp);
}
Looking at this article, it seems evident that ReadPixels() "will block the game thread until the rendering thread has caught up". The article contains sample code for a 'non-blocking' method of reading pixels (through removal of FlushRenderingCommands() and using a RenderCommandFence flag to determine when the task is done), but it doesn't significantly improve the performance: the rate at which images are saved is slightly higher, but the game thread still runs at about only 20 FPS, thus making it really hard to control the UAV. Are there any more efficient asynchronous methods that can achieve what I am trying to do, perhaps, say, in a separate thread? I am also a little confused as to why the code has no trouble streaming those images on-screen as fast as possible, but saving the images seems way more complicated. It's fine even if the images are saved to disk only at 15 Hz or so, as long as it doesn't interfere with the game's native FPS too much.
You can move the save-to-disk operation from Game thread to other thread.
Please check Async.h for detail
The limitation for thread is that you could not modify/add/delete uobject/uactor in other thread.
Multi-thread for UE4
I'm very late to the party, though in case anybody is still having issues with this: I built a non-blocking version inspired by code of AirSim's and UnrealCV's plugins because I had some serious compilation and versioning issues with those.. but needed a smoothly running camera while capturing images myself. This is also based on the async.h class of unreal API provides as the accepted answer suggested.
I setup a tutorial repo for this:
https://github.com/TimmHess/UnrealImageCapture.
Hoping it may help.
(...) it seems evident that ReadPixels() "will block the game thread until the rendering thread has caught up"
Using functions that try to access and copy GPU texture data is always a pain. I found that completion time of these functions depends on hardware or driver version. You could try to run your code on different (preferably faster or newer) GPU platform.
Back to code: to bypass single thread issue I would try to copy UTextureRenderTarget2D to UTexture2D using TextureRenderTarget2D::ConstructTexture2D method. When you get your image copied (I hope it take much faster) you could push it to consumer thread at 15 FPS ratio. Thread can be created using FRunnable or Async engine module (using so called Task Graph). Consumer thread could access cloned texture by using texture's PlatformData->Mips[0]->BulkData. Make sure that you are reading texture data between BulkData->Lock(...) and BulkData->Unlock() calls.
I'm not sure, but it could help because your copied texture will be not used by render thread so you could lock it's data without any blocking on render thread. I'm only worried about thread safety of Lock and Unlock operation (didn't found any clue), should be possible unless there are engine RHI calls.
Here is some related code that could be helpful.
Perhaps you should store screenshots in a TArray until the "game" is done, then process all stored data?
Or look at taking a screenshot from the drone camera instead of manipulating the pixel data? I assume the left and middle drone camera images are material-modified versions of the base camera image.
When you save an image, is it writing an image-format file or a .uasset?
Lastly - and this is a complete shot-in-the-dark - create a custom UActorComponent, add it to the drone, and make it watch for some instruction from the game. When you want to write an image, push the RenderTarget data to the custom UActorComponent. Since actor components can tick on any thread (using BCanTickOnAnyThread=true in the constructor, I think that's the variable name), the actor component's tick can watch for the incoming image data and process it there. I've never done it, but I have made an actor component tick on any thread (mine was checking physics).

Can't figure out what is causing this unending Recalculate Style loop

A client sent me an email saying that he noticed his computer was sluggish, and when he ran diagnostics he determined the cause was that his webpage was using up a bunch of CPU. In trying to debug why his site might be using so much CPU on his computer, I noticed while using Chrome that nothing was happening in the Console, but that in the Timeline, there is an unending loop of "Recalculate Style, Update Layer Tree, Composite Layers" despite nothing happening on the webpage.
Screenshot of timeline: http://i.imgur.com/kW6CedU.png
I tried searching how to determine the cause of this, and found that Canary might help, so I tried the Timeline in Canary and didn't see anything different.
I've read it can be from CSS transitions being written as transition:all instead of the actual property that needs to be transitioned, so I changed all instances of transition:all in the CSS to a singular target (transition:height for example) and still this loop continues.
I'm also not certain that this loop is what is causing his CPU to be taking a hit, but it's my best guess. I noticed that the website constantly had the "loading" circle animation in the window's tab for Chrome, but now it's not doing that anymore. I'm not sure if it's because I changed the CSS transition rules that it isn't constantly "loading" now, nor am I sure it has anything to do with the CPU usage.
Any advice appreciated.

Iphone: app action slow first time then fast

I have noticed that every single user interface action which is done for first time is slow. The very same action the next time is fast.
It deals with the sdk embedded functionality such as the camera, or my own functionalities such as my opengl button animations.
I have read that building for running could solve the problem, but for my case it doesn't.
Anyone has met a similar phenomena ? and how did you address it ?
Cheers,
Stéphane