"Object reference not set to an instance of an object"
code: https://github.com/axololly/chess/tree/main/Board.cs#L1073
not sure why this is happening. i changed the
Board
from a class
to a struct
so it's no longer heap allocated (used in an engine, so these things matter) and now it's raising weird errors like thisGitHub
chess/Board.cs at main · axololly/chess
A chess move generator I made over the summer because my friends didn't want to go out with me. - axololly/chess
29 Replies
$debug
Tutorial: Debug C# code and inspect data - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
Seems like mailbox might be null
Or
index
th item of itits not tho
in the constructor, i make it not null
even VSCode says that it's not null there
What does the debugger say?
haven't used it
worked on a python project instead
lemme take a look
this is for VS
i dont use VS
VS Code also has some sort of a debugger
So use that
its giving me literally the exact same error as in console
Place a breakpoint
See what the values are
Step through the code to see why they are what they are
aka debug
the fuck is this
You not running the debugger is what it is
i just ran it and it gave me a richer text version of the error message in console
Place a breakpoint where the
Maibox
is set
See if it gets hit
Step through the code
See if maybe this bit of code executes before mailbox gets setSee if there's no off-by-one errors
Etc
See what
index
is on each iteration
And what is at that index in the mailboxdebugger did jack shit
turns out that its inventing a new base overload
i have this:
but it thinks its this:
Debugger does what you tell it to do. It doesn't magically fix your code, it lets you gain insight into your code as it runs
That you don't know how to use it and refuse to learn is not the debugger's fault
explaining why im too stupid to use a debugger is not helping me fix my problem
why is there a parameterless constructor
Probably a quirk of structs
can i override it?
or is it stuck like that?
Not sure if it even is the case
I don't really use structs all that often
Let alone such humongous ones
how much data is in board?
i suspect it shouldn't be a struct in the first place
and yes structs always have an implicit parameterless constructor
yeah that's definitely too big to be a struct
just make it a class, a struct isn't giving you any benefits here and it may actually be worse
if you don't know why you're making something a struct just make it a class, that's a good rule of thumb
Here is the reference on where the parameterless constructor came from:
https://github.com/dotnet/csharpstandard/blob/standard-v6/standard/structs.md#1549-constructors
there are other behavior differences that can cause problems if you change an existing class to a struct. Like if someone passed your Board to a method that change some of the state, the caller would no longer see the changes after the method returns. So you might want to leave it as class for backwards compatibility, in addition to the reasons Jimmacle mentioned.
GitHub
csharpstandard/standard/structs.md at standard-v6 · dotnet/csharpst...
Working space for ECMA-TC49-TG2, the C# standard committee. - dotnet/csharpstandard