I am making a path finding algorithm for my newest project (A*) and got it to work but I know I can make it work more effective and I tried making a Heap in hopes of improving the run time. the issue was every time I tried running my game unity would just freeze and I had to restart my pc. Is there some issue with Unity and Heaps?
#Tired making a Heap in C# but got issues. (SOLVED)
1 messages · Page 1 of 1 (latest)
No, of course not. Heap is just a piece of code, nothing special regarding Unity. If the piece of code doesn't work, it has a bug in it. If Unity freezes, it's more than likely that your code makes an infinite loop that never stops eating all the resources needed to run the engine (the engine will move on only after all scripts are executed, one script never completing on the main thread will cause everything inside the engine freezing forcing you to shut down the engine from Task Manager). If you suspect certain loop to be the problem, you can place a breakpoint inside it and enable the debugger so that when you run the code, you will see what happend step by step and figure out the problem. You can always post the code here so we can try to figure out together what's the problem (preferably with a code block or paste site). Without the code it's impossible to help any further. TLDR: post your code here if you need further guidance
so here is the code for my my heap
here is the weird part I added the debug.log part on the two main loops to see which one is being spam (aka stuck in) but none of them were being called
also sorry for taking long to post, I made this post before I went to bed
[]cb
Use codeblocks to send code in a message!
To make a codeblock, surround your code with ```
To use C# syntax highlighting add cs after the three back ticks.
For example:
```cs
Console.WriteLine("Hello World");
```
Produces:
Console.WriteLine("Hello World");
To send lengthy code, paste it into https://paste.myst.rs/ and send the link of the paste into chat.
Well, that's not unexpected at all. When you call Debug.Log, unity doesn't immediately draw the message to the console (which makes sense because that would make it horribly slow). I assume the messages go into some sort of queue and the console is then updated only once in a while. By quick look at your code it seems likely that it's either SortUp or SortDown that gets stuck in a loop as you have noticed but instead of Debug.Loging from the loop you should place a checkpoint there and properly debug the code to see what it does and why the excecution never breaks out of the loop
got it will try making a checkpoint
hey I found the error and the loop seems to be stuck in the sortUp method
what seems to be the thing is the same object is being compared with it self but some how return a value greater than 0?
it works for the first time but it gets stuck in the second time going through it
oh I found a mistake
so in the tiles compareTo method
it should go compare their f value with the other f value and if both are the same than check their h value
but I was comparing tile one h value with tile two f value
The problem is solved 
so the problem was not the heap but with the compare method lol @keen otter thanks telling to add check points
wait how do I close this post and saying the problem is solved?
Often times more useful that Debug.Log (especially with infinite loops Debug.Log is pretty useless). I don’t think you have to close the post yourself, if you can edit the title, you could add SOLVED there but afaik it doesn’t really matter either way