CosmosOS / Cosmos

Cosmos is an operating system "construction kit". Build your own OS using managed languages such as C#, VB.NET, and more!
https://www.goCosmos.org
BSD 3-Clause "New" or "Revised" License
2.92k stars 550 forks source link

Dictionnary TryGetValue() function provokes an invalid OpCode #2382

Open selkij opened 2 years ago

selkij commented 2 years ago

Area of Cosmos - What area of Cosmos are we dealing with?

Dictionnarirs

Expected Behaviour - What do you think that should happen?

It should get the value from the key correctly

Actual Behaviour - What unexpectedly happens?

CPU exception Invalid OpCode

Reproduction - How did you get this error to appear?

20220816_123519.jpg

Version - Were you using the User Kit or Dev Kit? And what User Kit version or Dev Kit commit (Cosmos, IL2CPU, X#)?

Devkit from last month I think? I dont have internet on my pc

GoldenretriverYT commented 2 years ago

Dictionaries aren't fully supported as far as I know, at least I had problems as well.

Therefore I made a custom dictionary implementation which just uses 2 lists, it isn't fully-featured, standard-conforming or fast, but it should work. Multi-threading isn't a thing in Cosmos as of now anyway, but if it ever gets added, I would recommend not using this implementation anymore.

https://github.com/GoldenretriverYT/spaghettoOS/blob/main/spaghettoOS/Utils/CustomDict.cs TK (the Key type) has to inherit IComparable, which every Enum does. So it should, in theory, work.

Here is an example where I use my CustomDict: https://github.com/GoldenretriverYT/spaghettoOS/blob/main/spaghettoOS/Applications/ProcessManager.cs

selkij commented 1 year ago

Ill check that when I have time

AnErrupTion commented 1 year ago

After further debugging, it looks like this happens because System.Enum.GetHashCode() throws NotImplementedException.