What exactly happens when you press the "play" button in Unity? - process

As soon as you hit "Play" what happens in the background of the software? The code is already compiled and ready at this point. So when I press "Play" the code gets executed. What other things occur along with this?
I have this question as an assignment and would really like to know. Thanks. :)

Actually everything is loaded by script. This graph explains the process. Also the links below can be useful for you to understand all the background process.
Execution Order of Event Functions
Overview: Script compilation

Asking what happens when you press Play is like asking Coke to reveal the drink recipe. This is what they sell. You got that as assignment, fact is you can say anything and your teacher would lie to tell you wrong, since he does not know either (except if he works for a company that bought the source code of the engine).
What you can say, is that the OpenGl/DirectX API is initialised, registration of all event to the OS like Input, application data and so on, then all the Engine functioning, registering of the needed classes in memory, init of the physics, parsing of the opening scene YAML file, creation of the content and placement in space, for each item, if a MonoBehaviour, registration of all callbacks, all the debug code related to profiler and stack tracing, crash reports and many more...
Those are the obvious ones and I cannot have any clue of what is going on without using a tool to decompose the code. Problem, it is against the EULA and then illegal.

Related

IntelliJ/PhpStorm - How to use IDE scripting engine as a GitHub Copilot completion capture/fix?

I've been trying to find any type of documentation or examples on how to use the "IDE scripting engine" (or other quick methods of enhancing PhpStorm/IntelliJ IDEs) and found literally nothing that works.
I'm hoping for a bit of a guideline, maybe a snippet that leads in the right direction.
What I want to do:
When pressing Ctrl + Tab (shortcut for GitHub Copilot completion) I want my custom-script to wait for the completion to be inserted into the IDE code.
I want to immediately remove the code again and display it as a completion suggestion (should be quick).
Now I want to press a shortcut to accept the completion word by word until finished.
The possibly biggest problem of Copilot with countless of bug/feedback/feature reports since 2021 is that it inputs tons of code when people just want a tiny part. Like half a line. So users of it are forced to accept 12 lines of bad code, remove all the bad parts.
The reason probably is their marketing, they take those 12 lines (11 of them garbage) as efficiency improvement (12 lines of code accepted). So they don't fix it.
I want to fix it using the above method, the easiest approach would be the most welcome one.
Here is the only available data on the IDE Scripting console:
https://www.jetbrains.com/help/idea/ide-scripting-console.html
However, none of the examples even worked and there are barely any.
Here are the linked examples:
https://gist.github.com/gregsh/b7ef2e4ebbc4c4c11ee9#file-samples-groovy
Nothing of that worked either, various errors usually already in the first "imports" and no examples in "javascript"
Here is the finished code, I switched to Kotlin and from the dysfunctional scripting console to "LivePlugin".
https://github.com/cmp-nct/Stewardess
Stewardess takes over the completions through a new shortcut and plays them in word by word.
Also shows the Copilot internal status as temporary hint notification when it changes.

Labview Program changes behavior after looking at (not changing) the Block Diagram

My Labview Program works like a charm, until I look at the Block Diagram. No changes are made. I do not Save. Just Ctrl+E and then Ctrl+R.
Now it does not work properly. Only a Restart of Labview fixes the problem.
My Program controls two Scanner arrays for Laser Cutting simultaneously. To force parallel working, I use the Error handler and loops that wait for a signal from the Scanner. But suddenly some loops run more often than they should.
What does majorly happen in Labview when I open the Block diagram that messes with my code?
Edit:
Its hard to tell what is happening without violating my non-disclosure agreement.
I'm controlling two independent mirror-Arrays for Laser Cutting. While one is running one Cutting-Job, the other is supposed to run the other Jobs. Just very fast. When the first is finished they meet at the same position and run the same geometry at the same slow speed. The jobs are provided as *.XML and stored as .net Objects. The device only runs the most recent job and overwrites it when getting a new one.
I can check if a job is still running. While this is true I run a while loop for the other jobs. Now this loop runs a few times too often and even ignores WAIT-blocks to a degree. Also it skips the part where it reads the XML job file, changes the speed part back to fast again and saves it. It only runs one time fast.
#Joe: No it does not. It only runs once well. afterwards it does not.
Youtube links
The way it is supposed to move
The wrong way
There is exactly one thing I can think of that changes solely by opening the block diagram.
When the block diagram opens, any commented-out or unreachable-code-compiler-eliminated sections of code will load their subVIs. If one of those commented out sections of code were somehow interfere with your running code, you might have an issue.
There are only two ways I know of for that to interfere... both of them are fairly improbable.
a) You have some sort of "check for all VIs in memory" or "check for all types in memory" that you're using as a plug-in system. When the commented-out sections load, that would change the VIs in memory. Such systems are not uncommon when parsing XML, so maybe.
b) You are using Run VI method for some dynamically invoked VI to execute as a top-level VI, but by loading the diagram, it discovers that it is a subVI of your current program. A VI cannot simultaneously be top-level and a subVI, so the call to Run VI returns an error.
That's it. I can't think of anything else. Both ideas seem unlikely, but given your claim and a lack of a block diagram, I figured I'd post it as a hypothesis.
In the improbable case someone has a similar problem. The problem was a xml file that was read during run time. Sometimes multiple instances tried to access it and this produced the error.
Quick point to check: are Debug and "retain data in wires" disabled? While it may not change the computations, but it may certainly change the timing of very tight loops, and that was one of the unexpected program behaviors, OP was referring to.

On Smalltalk IDEs (Squeak, VisualWorks, etc), how can you navigate away from a message's code you're working on to inspect another?

In every IDE I've tried so far, if I'm partway through writing a message and need to look at the code of another, the browser asks me if I want to save. But if I say I do want to save, it actually tries to compile/syntax check the code, and refuses to perform the save if it does not pass. The only way to view the source of another message seems to be to say "no" to save and have everything wiped. How can I look at another class incidentally, or save code I am partway through working on that might not build right now?
Smalltalk is a multi-browser system. You'll need to have lots of different browsers open. Smalltalk is opinionated. The system browser (Nautilus) doesn't make it easy to view long methods, steering you towards writing short ones. It doesn't make it easy to have non-compiling code in a method, to steer you towards making small changes.
Experimental/prototypical code you might want to have in a Workspace/Playground. That can save to disk.
We are aware that it is an issue for people new to Smalltalk. We tried some fixes, they were a lot worse.
For now there is no easy way to do that. The two easiest opting are
Make the current method syntactically correct and save it.
Open another browser. If you want to see a class or method that is in your current code, you can cmd+click it or use "browse it", "implementors of", shortcuts that will open another window.
Also in pharo you can use GTSpotter to quickly find what you are looking for and preview its source code
When you say "this seems like a pretty huge thing to be missing,
and it could be gotten around by just having the option to use
a regular editor" I'm afraid you've entirely missed the point.
Understandable, though -- happens to us all.
Or did. Perhaps it was long ago, but we
were all there.
You might be thinking about the task in terms of
scrolling a giant text up and down to find what
you want. Scroll up -- read a little -- scroll back --
and continue making your changes.
And when you say " I can't imagine any circumstance
where it is OK, in pursuit of any agenda, to throw away
the coder's work against their will "
you are spot on correct, of course.
Imagine -- scrolling around, making dozens of little changes,
and before you've saved them -- poof -- they're all thrown away --
a mistake, perhaps, but completely against your will.
That would be awful. We're agreed.
(In fact, the editor I'm using to type this
is like that -- I can scroll around the whole thing,
making little improvements, all over, but it could
all go --poof-- and disappear, All of it.
Fairly common occurrence, when editing the web.
)
So let's try another run through that same task.
You get one little teensy, DUMB AS A POST editor,
where you can only see one thing at a time.
And now you just want to scroll somewhere else,
for a moment, and come right back.
Which actually means that
you are attempting to look up a second method,
while already changing a first method
(which would require the browser toforget the
context of the first method, and move to the second).
The browser does not know how long you will be away
from this context. You might go chaining along from
place to place, stop and read an email, take a call,
and go to lunch.
So, the browser cautions
"Hey - want to save this first?"
as if to say:
"
Hey - I can't imagine any circumstance where it is OK,
in pursuit of any agenda, to throw away the coder's work
against their will.
So listen up, coder.
You want to save this first?
"
But you can't save it.
You must first look something up.
Conundrum.
Ah-ha! There is a list of methods in that other pane.
One of them is highlighted.
Not those -- that one.
Double click that one.
The one you're already in.
As if to say
" Thanks. Good catch.
Yes, I know - can't though.
I need to change contexts.
You stay right here.
And give me another context
to go wandering about in.
please.
"
Soon, I expect, they'll start actually talking.

Track all ObjC method calls?

Sometimes when looking at someone else's large Objective-C program, it is hard to know where to begin.
In such situations, I think it would be helpful to log every call to every non-Apple method.
Is there a way to do that? Basically, make one change in some central place, and log every method that is called. Preferably limited to non-Apple methods.
You can set the environment variable NSObjCMessageLoggingEnabled to YES. This will write a log of all message sends in the folder /tmp/msgSends-xxx.
You could add a symbolic breakpoint to objc_msgSend(), and have it log the second parameter without stopping.
How to do it for your own methods only though is a toucher task. Maybe if you could inspect the class name being called and do some magic to have a conditional breakpoint for only calls where the class' prefix matches your own?
I don't think logging every single call is practical enough to be useful, but here's a suggestion in that direction.
On a side note, if it's a large program, it better have some kind of documentation or an intro comment for people to get started with the code.
In any case, every Cocoa application has an applicationDidFinishLaunching... method. It's a good place to start from. Some apps also have their principal (or 'main window') class defined in the Info.plist file. Both these things might give you a hint as to what classes (specifically, view controllers) are the most prominent ones and what methods are likely to have long stack-traces while the program is running. Like a game-loop in a game engine, or some other frequently called method. By placing a breakpoint inside such a method and looking at the stack-trace in the debugger, you can get a general idea of what's going on.
If it's a UI-heavy app, looking at its NIB files and classes used in them may also help identify parts of app's functionality you might be looking for.
Another option is to fire up the Time Profiler instrument and check both Hide missing symbols and Hide system libraries checkboxes. This will give you not only a bird's eye view on the methods being called inside the program, but also will pin-point the most often called ones.
By interacting with your program with the Time Profiler recording on, you could also identify different parts of the program's functionality and correlate them with your actions pretty easily.
Instruments allows you to build your own "instruments", which are really just DTrace scripts in disguise. Use the menu option Instrument >> Build New Instrument and select options like which library you'd like to trace, what you'd like to record when you hit particular functions, etc. Go wild!
That's an interesting question. The answer would be more interesting if the solution supported multiple execution threads and there were some sort of call timeline that could report the activity over time (maybe especially with user events plotted in somehow).
I usually fire up the debugger, set a breakpoint at the main entry point (e.g. - applicationDidFinishLaunching:withOptions:) and walk it in the debugger.
On OSX, there are also some command-line tools (e.g. sample and heap) that can provide some insight.
It seems like some kind of integration with instruments could be really cool, but I am not aware of something that does exactly what you're wanting (and I want it now too after thinking about it).
If one were to log a thread number, and call address, and some frame details, it seems like the pieces would be there to plot the call timeline. The logic for figuring out the appropriate library (Apple-provided or third party) should exist in Apple's symbolicatecrash script.

How to get rid of unmanaged code in VW 3.1d and ENVY

I have an old VW3/ENVY image with a parcel loaded as unmanaged code (exactly the situation Mastering ENVY/DEVELOPER warns against). Unfortunately, this problem happened a long time ago and it's too late to just "go back" to an image without the parcel loaded.
Apparently, there is a way to solve this problem (we have one development image where this has been solved, and there are normal configuration maps that contain the exact same code as the unmanaged parcel but they can't be loaded), but the exact way has long since been forgotten (and there are some problems with taking that particular dev image as the base for a new runtime image, so I need to find out how how to do it again).
In theory, it should be possible to remove the parcel and reload the code from a configuration map. In practice, all normal ways (using the ParcelBrowser or directly calling UnmanagedCode>>remove) fail. I even tried manually removing the offending selectors from the method dictionary, but past a certain point (involving a call to #primBecome:) the whole image hangs completely (I can't even drop into the debugger). I started hacking the instances of the classes and methods, hoping I'd trick ENVY into thinking that these particular methods are normal versioned code, but without any success yet.
Are there any smalltalk/envy gurus around that still remember enough of VW 3 to provide me with any pointers?
Status update
After a week of trying to solve the problem I finally made it, at least partially, so in case anyone's interested...
First, I had to fix file pointers for the umnanaged code (otherwise, all everything that tried to touch the methods would throw an exception). It looks like ENVY extends Parcel so that, in theory, all integer file pointers are changed to ENVY's void filepointer when loaded, but in my case, I had to do it manually (a Parcel provides enumeration for all selectors it defines). Another way would be to tweak the filePointer code, but that can't easily be done automatically on every image where it's needed.
Then, the parcel can be discarded, which drops the parcel information, but keeps the code. The official "Discard" mechanism needs to have a valid changes file (which envy doesn't use so it has to be set manually, and reset afterwards) and the parcel source (which we fortunately had).
To be able to make any changes to the methods (either manually, or via loading an application or class from ENVY), they need to get rid of their unmanaged status. This can be done by manually tweaking TheClass>>applicationAssocs (I also got rid of all references to the classes in UnmanagedCode sich as timestamps, and removed the reference to the discarded parcel). I actually had some info on how to get to this point from my boss, but I haven't been able to understand the instructions until I almost figured it out by myself.
This finally allowed me to load and reload all the Applications that contained the classes. In theory. In practice, the image still hung completely whenever I tried to load a newer version of the Application (that contained the code formerly in the parcel).
It turned out that the crashes had absolutely nothing to do with the code being unmanaged, but with the fact that the parcel in question modified InputState>>process:, where it caused an exception due to a missing and/or uninitialized class variable (the InputState>>initialize method wasn't called until after the new process: method was in place). I had to modify the Notifier class to dump all exceptions to a file to find out what was going on. Adding the class variable to the source of the class (instead of adding it via reflection), suspending the input processing thread via toBeLoadedCode and starting it again in the loaded method and creating a new version of the application solved even this problem.
Now everything works, in theory. In practice it's still unusable, because reloading the WindowSystem or VisualworksBase applications causes their initialization blocks to run, and a whole lot of settings are reset to their defaults - fonts and font sizes, window colors, UI settings... And there doesn't seem to be any way to just save the settings to a file and load them later on, or just to see what all the settings are (either the official Settings menu doesn't show everything, or we have a heavily tweaked image... so much for reconstructing it from scratch). But that's a completely different question.
Well, normally the recommendation would be that you should be able to rebuild your development image from scratch by loading your code from the repository. But if you had that, then the answer would be simple, just discard that image and reload. I think it's been long enough that I've lost whatever knowledge I've had about how to mess with the internal structures to get it back, and it sounds like you've tried a lot of things. So, although it might be painful, figuring out the recipe to rebuild your development image by loading stuff from the repository sounds like it may be your best bet. It probably isn't all that horrible, there just might be a few dependencies on the image state, or special doits that need to be executed.
You also probably need to validate what's in the repository against what's in the image you're working from. If there was unmanaged code loaded and then someone modified it and saved it, it's not clear to me that it would have been saved to ENVY. So you probably want to audit everything that was unmanaged code and if it's been changed, save that to a repository edition.
Sorry I don't have any better answers.