Unity Crashes On LoadAll - c#

When I try to execute the following line of code, my unity3d Crashes without further nothice.
allmeshes = Resources.LoadAll("Meshes",typeof(Mesh)) as Mesh[];
Could it be because it wants to Load too much data at once or is it something different?

Related

C# Service doesn´t open script

(Sorry for bad english i´m german)
I´m writing a service for a bigger project, the task for it is to check a folder for files and then call a Powershell-Script and give it the name of the file. This part is a bit unclean because i use a Powershellinstance to open a Powershell-Script. The Service itself is working, i tested it with different code to execute and the code to call the Script works when executed by a normal program, but when i let the service call the Script it seems like he just skips that part. The executionpolicy of the Script isn´t the problem. I post the part of the code that is supposed to open the Script. Any ideas?
static void Do()
{
Thread.Sleep(5000);
DirectoryInfo dir = new DirectoryInfo(#"C:\RecosDienstTest"); // Anpassen (json)
try
{
foreach (var datei in dir.EnumerateFiles())
{
using (PowerShell PowerShellInstance = PowerShell.Create())
{
PowerShellInstance.AddScript("C:\\Users\\ZO066\\Desktop\\test.ps1 " + datei.FullName); // Anpassen (PS-Script)
PowerShellInstance.Invoke();
if (PowerShellInstance.Streams.Error.Count > 0) { break; }
}
File.Move(datei.FullName, #"C:\RecosDienstTest2\" + datei.Name); // Anpassen
}
} catch {}
Do();
}
Boys, I finally got it! And I feel so stupid now... In the act of fixing this I changed the code so often, used different methods to open the script, I even destroyed my Visual Studio and had to reinstall it. At some point i decided to open txt-files instead of PS-Scripts but had exactly the same problem: Nothing happend and no Errors what-so-ever. The reason is that when a Service opens something, it just runs in the background no matter what it is(I had a few hundred Notepadinstances opened). The strange thing about this, and the reason why I didn´t thought of it: That happens to the whole chain. The service opened a script that opened a txt-file, but because the script was started by the service the txt-file is also opened in the background. I dont know why that is but I´m glad that I atleast found out why the fck nothing happened.

uglify crashing after running child_process.execFile

EDIT 2
I "solved" the problem, but I don't want to post it as an answer b/c it doesn't explain what actually happened. In the code for the .NET resourceReader.exe I use
Console.OutputEncoding = System.Text.Encoding.UTF8;
to output the internationalized resources to stdout in unicode. If I reset the encoding at the end of my program with
Console.OutputEncoding = System.Text.Encoding.Default;
then I don't get any errors in Node. If I don't reset it, I get the error described in the original question. It seems that .NET is somehow messing up some of the output encoding settings on the cmd.exe and causing the subsequent node run to fail!
EDIT
I narrowed down the error to being caused by resourceReader.exe. It's a.NET program which reads some resource streams out of the .NET assembly and prints them to the stdout using Console.WriteLine. I added Console.OutputEncoding = System.Text.Encoding.UTF8 to resourceReader.exe because some of the resources are in non ASCII letters and that's whats causing the crash in grunt!
If I take that line out, the task doesn't crash, but the resources show up in non printable ASCII characters! Also, the crash only happens if I actually print non-ASCII to sdtout. If I don't print them, it doesn't error.
ORIGINAL
I added a step to my Gruntfile which uses child_process.execFile to run an read some data from an external program and uses it in the build. Now whenever I run my build, it runs fine the first time, but crashes the second time!
Here's the output from the crash (this is during the uglify task):
File build/Scripts/NDB.contacts.min.js created: 16.85 kBevents.js:85
throw er; // Unhandled 'error' event
^
Error: This socket is closed.
at WriteStream.Socket._writeGeneric (net.js:656:19)
at WriteStream.Socket._write (net.js:709:8)
at doWrite (_stream_writable.js:301:12)
at writeOrBuffer (_stream_writable.js:288:5)
at WriteStream.Writable.write (_stream_writable.js:217:11)
at WriteStream.Socket.write (net.js:634:40)
at Log._write (C:\...\node_modules\grunt\node_modules\grunt-legacy-log\index.js:161:26)
at Log.wrapper [as _write] (C:\...\node_modules\grunt\node_modules\grunt-legacy-log\node_modules\lodash\index.js:3095:19)
at Log._writeln (C:\...\node_modules\grunt\node_modules\grunt-legacy-log\index.js:166:8)
at Log.wrapper [as _writeln] (C:\...\node_modules\grunt\node_modules\grunt-legacy-log\node_modules\lodash\index.js:3095:19)
at Log.writeln (C:\...\node_modules\grunt\node_modules\grunt-legacy-log\index.js:177:8)
at Log.wrapper (C:\...\node_modules\grunt\node_modules\grunt-legacy-log\node_modules\lodash\index.js:3095:19)
at writeln (C:\...\node_modules\grunt\lib\grunt\fail.js:30:13)
at Object.fail.fatal (C:\...\node_modules\grunt\lib\grunt\fail.js:46:3)
at process.uncaughtHandler (C:\...\node_modules\grunt\lib\grunt.js:121:10)
at process.emit (events.js:129:20)
at process._fatalException (node.js:236:26)
at Task.runTaskFn (C:\...\node_modules\grunt\lib\util\task.js:250:7)
at Task.<anonymous> (C:\...\node_modules\grunt\lib\util\task.js:293:12)
at C:\...\node_modules\grunt\lib\util\task.js:220:11
at process._tickCallback (node.js:355:11)
Here's the code for the task which uses child_process.
function readAllCultures() {
var readDeferred = q.defer();
childProc.execFile("../tools/resourceReader.exe", function (err, stdout, stderr) {
if (err) throw new Error(err);
var cultures = JSON.parse(stdout);
readDeferred.resolve(cultures);
});
return readDeferred.promise;
}
Here's some things I discovered debugging that might be helpful
If I redirect the output of grunt (using either > filename or | process) it runs fine
When I redirect output, I never see the message from uglify that it created the main output only that it created the source map.
If I close and reopen my command prompt (cmd.exe) it works fine
I added a listener to the exit and close events of the child process using rdr.on("close", function() { console.log("close"); }); and the same for exit. Both events fire as expected in the first run.
Using Process Explorer, I can see node.exe open under the command prompt and close again when my command finishes running. There are no processes visibly "left open" under the command prompt.
The fact that the stack trace is ultimately showing a socket.write error is interesting. Nothing in the code you've provided suggests you are trying to write to a socket.
If we follow the stack down, we can see that it's actually grunt that is trying to write to a socket, as it's attempting to log an uncaught exception.
So, first your grunt task throws a currently unknown error, and then grunt itself errors because it can't tell you about it.
I would first try and log the error that occurs in your child process. Currently if there is an error present, you simply throw it without finding out what it is. It's likely that this is what grunt is trying and failing to log.
Replace
if (err) throw new Error(err);
With
if (err) console.error(err);
This will hopefully avoid the socket.write problem and give you specific information about what error is happening on the child process. What do you see?
Second, I would try using child_process.exec instead of child_process.execFile. This will spawn a shell and run resourceReader.exe inside of it (instead of running it directly). This might help avoid any problems you are encountering with the command still running/failing in the background, which could be the cause of the socket.write error.

Code Execution stops with no error

In my Form1_Load event, the code execution stops for no reason the middle of nowhere, and just finishes the loading process at that instance, showing the gui, this is the code and the line where it stops:
Downloadn("https://somelinkhere.com/file.txt","Init.txt");
Application.DoEvents();
List<string> links = new List<string>();
var lines = File.ReadAllLines("Init.txt"); //Code Stops and Gui Shows up after executing this code
links.Add(lines[0].Split('^')[1]);
links.Add(lines[1].Split('^')[1]);
links.Add(lines[2].Split('^')[1]);
links.Add(lines[3].Split('^')[1]);
The debugging process shows no errors, what could i be doing wrong ?
I wonder if an exception is being caught and swallowed somewhere, since by the sounds of it the program doesn't crash it merely skips some code. In Visual Studio, go to Debug\Exceptions, tick all the Thrown boxes and try again. If my suspicion is correct, this will identify the problem.

PrivateFontCollection hangs on initilizing

i have a client server application. i want to load a font from file in my server part.
here is my code to do that. but unfortunately it will hangs on new PrivateFontCollection(); line!!!!
note that this part is running in another thread.
string fontAdd = #"C:\ETLEngine\Languages\Fonts\BNazanin.ttf";
System.Drawing.Text.PrivateFontCollection privateFonts = new System.Drawing.Text.PrivateFontCollection();
privateFonts.AddFontFile(fontAdd);
var mapFont = new Font(privateFonts.Families[0], 12, FontStyle.Bold);
please help me get out of this.
is there any alternative way for loading font from files?
Actualy I did write a console application which just do the code above, and everything works completely fine!! i got this sample code from msdn and stackoverflow, but i don't know why it doesn't work in my server side application!!! it doesn't produce an error, i set a break point on that line, and hit F10 or F11 and then its going to execute that line but never comes back to execute next line! and the thread still is in running state, not terminated or something else...! that's it!!!

Drawing a line with DirectX C#

I'm trying to draw a simple line using DirectX9 and encountered the following:
When the code reach the line:
Device device = new Device( some example code I'v found);
The location of the form is changing in a periodic manner, meaning every time the program executes. I see (in debug mode) that the form location properties change and return to their original values on the 6th execution. Why?
Upon resizing the code throw a general exception pointing to the line
device.DrawUserPrimitive(..)

Categories

Resources