C
C#7mo 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
TheRanger7mo ago
$details
MODiX
MODiX7mo 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
nut7mo 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
nut7mo ago
No description
TheRanger
TheRanger7mo ago
are you in release mode? also we usually use silk.NET(Most Recommended) or OpenTK
nut
nut7mo 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
TheRanger7mo ago
lock you into their windowing system ?
nut
nut7mo ago
you know, extend IWindow, all your code goes in OnUpdateFrame, OnRenderFrame, etc
TheRanger
TheRanger7mo ago
ah
nut
nut7mo ago
i just wanted a more c style glfw setup
TheRanger
TheRanger7mo ago
never used OpenGL.NET so no idea
nut
nut7mo 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
TheRanger7mo ago
did you follow the tutorial exactly? perhaps you missed something
nut
nut7mo ago
yeah, ithink
TheRanger
TheRanger7mo 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
nut7mo ago
where did you find that?
TheRanger
TheRanger7mo ago
stack overflow
nut
nut7mo ago
could you link it my glfw might be the problem (somehow?? idk)
TheRanger
TheRanger7mo 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
TheRanger7mo ago
ur issue probably is, it doesnt know which window to use ClearColor on
nut
nut7mo 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
TheRanger7mo ago
GL.Initialize(); Glfw.MakeContextCurrent(window); but the code calls Glfw.MakeContextCurrent(window); before GL.Initialize(); in the stack overflow page
nut
nut7mo 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
TheRanger7mo ago
nint or int?
nut
nut7mo ago
nint dont know exactly what that is
TheRanger
TheRanger7mo ago
thats unsafe, the overload is probably meant for something else nint is IntPtr
nut
nut7mo ago
i figured
TheRanger
TheRanger7mo ago
or simply a pointer like in C
nut
nut7mo ago
thats why i tried the different overload
TheRanger
TheRanger7mo ago
yeah the color values are normalized 0 to 1 instead of 0 to 255
tannergooding
tannergooding7mo 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
Perksey7mo ago
Why not? Silk doesn’t lock you into any windowing system.
nut
nut7mo 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
Perksey7mo ago
no it doesn’t, you can use silk without the windowing class what trouble are you having?
nut
nut7mo 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
Perksey7mo 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
nut7mo ago
how can i get this ref to the first member? nvm i just bit my tongue and used pointers