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