really confused with an error

Hi , this error has only just started appearing in my code:

Exception in thread "main" java.lang.RuntimeException: No OpenGL context found in the current thread.
	at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124)
	at org.lwjgl.opengl.GL11.glClear(GL11.java:585)
	at com.Core.Gamecore.render(Gamecore.java:171)
	at com.Core.Gamecore.start(Gamecore.java:118)
	at com.Core.Gamecore.<init>(Gamecore.java:42)
	at com.Core.Gamecore.main(Gamecore.java:46)

The class that is causing the issue is this one: please dont comment on how efficient it is.

public class Button {//Mostly complete
	private vertex2d position,aposition;
	private int type;
	private GB graphicsp,graphicsd,textinf;
	private boolean pressed;
	private String text;
	private int pos;
	private text t;
	private Gamecore core;
	public Button(Gamecore core,int x, int y,String text, int type,int pos){
		position = new vertex2d(x,y);
		aposition = new vertex2d((core.width/2) + x,(core.height/2)+y);
		this.text = text;
		this.type = type;
		pressed = false;
		this.core = core;
		this.pos = pos;
		graphicsp = new GB(core);
		graphicsd = new GB(core);
		graphicsd.createobject(core.world.shape.rect(core.button.getcoords(0, 0, 143, 28), 143, 28), core.button.gettexture(),1);
		graphicsp.createobject(core.world.shape.rect(core.button.getcoords(0, 30, 143, 58), 143, 28), core.button.gettexture(),1);
		graphicsd.translate(x, y);
		graphicsp.translate(x,y);
		t = new text(core);
		textinf = t.getfontbatch(text);
		
	}
	public vertex2d getposition(){
		return position;
	}
	public void setposition(vertex2d vert){
		position = vert;
	}
	public void press(){
		if(type == 0){
			pressed = true;
		}
		if(type == 1){
			if(pressed){
				pressed = false;
				return;
			}
			else{
				pressed = true;
				return;
			}
		}
	}
	public void unpress(){//only use on non toggle butons
		pressed = false;
	}
	public boolean checkpress(){
		//if(core.mx>= aposition.getx() && core.mx <= aposition.getx() +128){
			//if(core.my >= aposition.gety() && core.my <= aposition.gety() + 26){
				
					//press();
					return true;
				
		//	}
		//}
		//unpress();
		//return false;
	}
	public void render(){
		if(!pressed){
			graphicsd.render();
		}
		else{
			graphicsp.render();
			
		}
		textinf.render();
	}
	
	public int getpos(){//returns stored array position if defined
		return pos;
	}
	public void destroy(){
		graphicsp.destroy();
		graphicsd.destroy();
		textinf.destroy();
	}
}

Do you run the button rendering code in a separate thread than the main thread?

This error occurs when you use call opengl methods in a thread that does not have a opengl context. Your probably getting the error because your opening a thread and creating one of these objects in it, which would cause the error because the object calls opengl methods. I think another possible cause of the error would be if you have destroyed the opengl context and then call opengl methods, but I could be wrong. Maybe your getting the error because you create one of these objects before creating the opengl context.

Unrelated to your error :
By convention Java class names that are not basic data types begin with a capital letter, and methods use the camelCaseNamingConvention :slight_smile:

Its not run in a seperate thread, I create two VBOS for each image state(I know) , here is the code I use for cycling . The error occurs when I call :GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

Do you call this before you create the Display?

Display is creatd within init, I call clear at the beggining of each render(after the last render)

This error means that you’re calling opengl commands, when Display (in lwjgl’s situation) hasn’t been yet created. This means that you need to delay your code which causes the error to be executed after the context is made.

public class Game {//handles the entire game loading of major events , Gamecore will be a render function and tick updater does not include objects
	private Gamecore core;
	private World world;
	private GUI screen;
	private GUI loading;
	private int[] buttons = new int[200];
	private GUI options;//unused
	
	public Game(Gamecore core){
		this.core = core;
		this.world = core.world;
		core.logger.log("Game event handler loaded");
	//	init();
	//	setuploading();
	}
	private void init(){
		for(int i = 0; i < buttons.length;i++){
			buttons[i] = -2;
		}
		//loading = new GUI((int)core.width,(int)core.height,core);
		//screen = new GUI((int)core.width,(int)core.height,core);
	}
	private void setuploading(){
		buttons[0] = loading.addButton(-20, -20, "Play");
		buttons[1] = loading.addButton(-20,10,"Options");
		buttons[2] = loading.addButton(-20, 40, "Exit");
	}
	private void setupscreen(){
		
	}
	public void play(){
		
	}
	public void options(){
		
	}
	public void exit(){
		core.kill();
	}
	public void render(){
	//	loading.render();
	}
	public void tick(){
		if(loading.getbutton(buttons[0]).checkpress()){
			play();
		}
		if(loading.getbutton(buttons[1]).checkpress()){
			options();
		}
		if(loading.getbutton(buttons[2]).checkpress()){
			exit();
		}
	}
	public void destroy(){//used for cancelling events only. Object deletion occurs in map.
		
	}
	

}

package com.Core.graphics.GUI;

import com.Core.Gamecore;
import com.Core.graphics.GB;
import com.Core.graphics.vertex2d;

public class Button {//Mostly complete
	private vertex2d position,aposition;
	private int type;
	private GB graphicsp,graphicsd,textinf;
	private boolean pressed;
	private String text;
	private int pos;
	private text t;
	private Gamecore core;
	public Button(Gamecore core,int x, int y,String text, int type,int pos){
		position = new vertex2d(x,y);
		aposition = new vertex2d((core.width/2) + x,(core.height/2)+y);
		this.text = text;
		this.type = type;
		pressed = false;
		this.core = core;
		this.pos = pos;
		graphicsp = new GB(core);
		graphicsd = new GB(core);
		graphicsd.createobject(core.world.shape.rect(core.button.getcoords(0, 0, 143, 28), 143, 28), core.button.gettexture(),1);
		graphicsp.createobject(core.world.shape.rect(core.button.getcoords(0, 30, 143, 58), 143, 28), core.button.gettexture(),1);
		graphicsd.translate(x, y);
		graphicsp.translate(x,y);
		t = new text(core);
		textinf = t.getfontbatch(text); 
		
	}
	public vertex2d getposition(){
		return position;
	}
	public void setposition(vertex2d vert){
		position = vert;
	}
	public void press(){
		if(type == 0){
			pressed = true;
		}
		if(type == 1){
			if(pressed){
				pressed = false;
				return;
			}
			else{
				pressed = true;
				return;
			}
		}
	}
	public void unpress(){//only use on non toggle butons
		pressed = false;
	}
	public boolean checkpress(){
		if(core.mx>= aposition.getx() && core.mx <= aposition.getx() +128){
			if(core.my >= aposition.gety() && core.my <= aposition.gety() + 26){
				
					press();
					return true;
				
			}
		}
		unpress();
		return false;
	}
	public void render(){
		if(!pressed){
			graphicsd.render();
		}
		else{
			graphicsp.render();
			
		}
		textinf.render();
	}
	
	public int getpos(){//returns stored array position if defined
		return pos;
	}
	public void destroy(){
		graphicsp.destroy();
		graphicsd.destroy();
		textinf.destroy();
	}
}

Error is somewhere in there , I have no clue what is causing it . its all in one thread, I create the display before anything else.

According to the stack trace, the error is in Gamecore.java
Mind posting that?

well gamecore the display clear. when I disabled the Game class the errors stopped meaning it is coming from there.

Maybe the symptoms of the error come from Game, but Gamecore is where the error is, I’m pretty sure of it.

Can you show us the line where the error happens?

GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

Usually this happens when you try to use an OpenGL method without having the display created. Or there is no display in the current thread.

Try creating the display before clearing the colors or even using anything from GL**.

everything I us is created after create the display

Everyone is saying the same thing…
Its what is causing the error, in one way or another XD

the question is how do I solve it

We can’t answer that until we see the code.

Like they said, the error is cause by GameCore, not Game or Button. Therefore, we need to see that code in order to help.

Ok I have found out whats causing the error, I am somehow calling a core.kill() its causing an error because it was deleting something that wasnt there. It was an array indexing problem somehow , disguised as an odd thing.