C
C#8mo ago
nut

object reference not set to instance of object on a static method call

so im trying to use an opengl binding package (Veldrid.OpenGLBinding) but, when i call any of the methods, it says "Object reference not set to an instance of an object". I'm guessing I'm not using it right but it has absolutely zero documentation so I'm lost
37 Replies
TheRanger
TheRanger8mo ago
$details
MODiX
MODiX8mo ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
nut
nut8mo ago
public void Run()
{


GL.Initialize();
Glfw.Init();

window = new Window(800, 600, "W");

GL.ClearColor(255, 255, 255, 255);

while (!window.ShouldClose())
{
window.Clear();

window.SwapBuffers();
Glfw.PollEvents();
}
}
public void Run()
{


GL.Initialize();
Glfw.Init();

window = new Window(800, 600, "W");

GL.ClearColor(255, 255, 255, 255);

while (!window.ShouldClose())
{
window.Clear();

window.SwapBuffers();
Glfw.PollEvents();
}
}
I tried switching to OpenGL.NET and same issue GL.ClearColor throws this error
nut
nut8mo ago
No description
TheRanger
TheRanger8mo ago
are you in release mode? also we usually use silk.NET(Most Recommended) or OpenTK
nut
nut8mo ago
i didnt wanna use either of those because they lock you into their windowing system that i dont like i wanted to just use glfw windowing directly and it doesnt work in debug nor release mode
TheRanger
TheRanger8mo ago
lock you into their windowing system ?
nut
nut8mo ago
you know, extend IWindow, all your code goes in OnUpdateFrame, OnRenderFrame, etc
TheRanger
TheRanger8mo ago
ah
nut
nut8mo ago
i just wanted a more c style glfw setup
TheRanger
TheRanger8mo ago
never used OpenGL.NET so no idea
nut
nut8mo ago
do you know of anything that doesnt lock you into the windowing system i thought silk would work since it had glfw bindings but it didnt have any opengl bindings i could use
TheRanger
TheRanger8mo ago
did you follow the tutorial exactly? perhaps you missed something
nut
nut8mo ago
yeah, ithink
TheRanger
TheRanger8mo ago
found some code in so
Glfw.Init();
GLFWwindow window = Glfw.CreateWindow(1080, 720, "Yeet", null, null);
Glfw.MakeContextCurrent(window);
Gl.Initialize();
Glfw.Init();
GLFWwindow window = Glfw.CreateWindow(1080, 720, "Yeet", null, null);
Glfw.MakeContextCurrent(window);
Gl.Initialize();
perhaps you need to initialize it this way
nut
nut8mo ago
where did you find that?
TheRanger
TheRanger8mo ago
stack overflow
nut
nut8mo ago
could you link it my glfw might be the problem (somehow?? idk)
TheRanger
TheRanger8mo ago
Stack Overflow
How Do I Initialize OpenGL.NET with GLFW.Net?
I am trying to use OpenGL and GLFW in C#. I Have Installed NuGet Packages for GLFW.Net and OpenGL.Net. What I cannot for my life figure out, is how do I setup the context for OpenGL.Net with GLFW.N...
TheRanger
TheRanger8mo ago
ur issue probably is, it doesnt know which window to use ClearColor on
nut
nut8mo ago
Glfw.Init();
Window window = Glfw.CreateWindow(1080, 720, "Yeet", GLFW.Monitor.None, Window.None);
GL.Initialize();
Glfw.MakeContextCurrent(window);
GL.ClearColor(255, 255, 255, 255);

while (true)
{
Glfw.PollEvents();
}
Glfw.Init();
Window window = Glfw.CreateWindow(1080, 720, "Yeet", GLFW.Monitor.None, Window.None);
GL.Initialize();
Glfw.MakeContextCurrent(window);
GL.ClearColor(255, 255, 255, 255);

while (true)
{
Glfw.PollEvents();
}
this is what ive got now same crash
TheRanger
TheRanger8mo ago
GL.Initialize(); Glfw.MakeContextCurrent(window); but the code calls Glfw.MakeContextCurrent(window); before GL.Initialize(); in the stack overflow page
nut
nut8mo ago
the solution doesnt also somehow, a different overload of clearcolor fixes it if i use float,float,float,float instead of nint, nint, nint, nint it works ?? okayt then
TheRanger
TheRanger8mo ago
nint or int?
nut
nut8mo ago
nint dont know exactly what that is
TheRanger
TheRanger8mo ago
thats unsafe, the overload is probably meant for something else nint is IntPtr
nut
nut8mo ago
i figured
TheRanger
TheRanger8mo ago
or simply a pointer like in C
nut
nut8mo ago
thats why i tried the different overload
TheRanger
TheRanger8mo ago
yeah the color values are normalized 0 to 1 instead of 0 to 255
tannergooding
tannergooding8mo ago
IntPtr is not a pointer it is a pointer sized integer Int32 is 32-bits, Int64 is 64-bits IntPtr is ptr-bits
Perksey
Perksey8mo ago
Why not? Silk doesn’t lock you into any windowing system.
nut
nut8mo ago
silk makes you use its window class, and you can create a window andm ake your own event loop like you can with glfw but i switched to silk anyways and im still having trouble
Perksey
Perksey8mo ago
no it doesn’t, you can use silk without the windowing class what trouble are you having?
nut
nut8mo ago
why is it all unsafe? why arent there functions to upload uniform matices safely? why do i have to make an unsafe context, get a pointer to the matrix struct, and use that
Perksey
Perksey8mo ago
Any time you’re using anything that isn’t a C# function you are using unsafe, any library that tries to convince you otherwise is lying. Even if you don’t have to use the unsafe keyword, make no mistake it is unsafe. You shouldn’t try to hide from it just because it has a scary name. You are leaving the scary of the .NET runtime. however, we do provide overloads for using refs, so you could for example take a ref to the first matrix member instead The tutorials do not use these overloads tmk, they predate the overloads existence and we didn’t feel like it was a high priority to change them.
nut
nut8mo ago
how can i get this ref to the first member? nvm i just bit my tongue and used pointers