add yoga double free minimization
Some checks reported errors
studiorailgun/Renderer/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
austin 2024-08-28 21:36:46 -04:00
parent bca1789457
commit fc4730c24a
11 changed files with 97 additions and 75 deletions

View File

@ -6,6 +6,7 @@ import java.util.Map;
import org.joml.Vector2i; import org.joml.Vector2i;
import org.lwjgl.opengl.GL40; import org.lwjgl.opengl.GL40;
import electrosphere.engine.Globals;
import electrosphere.renderer.shader.ShaderProgram; import electrosphere.renderer.shader.ShaderProgram;
/** /**
@ -179,6 +180,7 @@ public class OpenGLState {
if(DISABLE_CACHING || program != activeShader){ if(DISABLE_CACHING || program != activeShader){
activeShader = program; activeShader = program;
GL40.glUseProgram(activeShader.getShaderId()); GL40.glUseProgram(activeShader.getShaderId());
Globals.renderingEngine.checkError();
renderPipelineState.setCurrentShaderPointer(activeShader.getShaderId()); renderPipelineState.setCurrentShaderPointer(activeShader.getShaderId());
} }
} }

View File

@ -9,11 +9,13 @@ import org.joml.Vector3f;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL30; import org.lwjgl.opengl.GL30;
import org.lwjgl.opengl.GL31; import org.lwjgl.opengl.GL31;
import org.lwjgl.opengl.GL40;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
import electrosphere.renderer.OpenGLState; import electrosphere.renderer.OpenGLState;
import electrosphere.renderer.RenderingEngine;
import electrosphere.renderer.shader.ShaderProgram; import electrosphere.renderer.shader.ShaderProgram;
/** /**
@ -158,7 +160,11 @@ public class LightManager {
public void bindBuffer(OpenGLState openGLState){ public void bindBuffer(OpenGLState openGLState){
//get position of lights object in shader //get position of lights object in shader
int bufferIndex = GL31.glGetUniformBlockIndex(openGLState.getActiveShader().getShaderId(), "Lights"); int bufferIndex = GL31.glGetUniformBlockIndex(openGLState.getActiveShader().getShaderId(), "Lights");
Globals.renderingEngine.checkError(); int glErrorCode = Globals.renderingEngine.getError();
//TODO: fix manually ignoring GL_INVALID_VALUE from call
if(glErrorCode != 0 && glErrorCode != GL40.GL_INVALID_VALUE){
LoggerInterface.loggerRenderer.DEBUG_LOOP(RenderingEngine.getErrorInEnglish(glErrorCode));
}
if(bufferIndex == ShaderProgram.INVALID_UNIFORM_NAME){ if(bufferIndex == ShaderProgram.INVALID_UNIFORM_NAME){
LoggerInterface.loggerRenderer.INFO("Tried to buffer light manager to shader that does not have it active."); LoggerInterface.loggerRenderer.INFO("Tried to buffer light manager to shader that does not have it active.");
} else { } else {

View File

@ -365,7 +365,6 @@ public class Mesh {
selectedProgram = shader; selectedProgram = shader;
} }
openGLState.setActiveShader(renderPipelineState, selectedProgram); openGLState.setActiveShader(renderPipelineState, selectedProgram);
Globals.renderingEngine.checkError();
} }
if(renderPipelineState.getUseLight()){ if(renderPipelineState.getUseLight()){

View File

@ -7,6 +7,7 @@ import electrosphere.renderer.RenderPipelineState;
import electrosphere.renderer.model.Material; import electrosphere.renderer.model.Material;
import electrosphere.renderer.model.Model; import electrosphere.renderer.model.Model;
import electrosphere.renderer.ui.elementtypes.DrawableElement; import electrosphere.renderer.ui.elementtypes.DrawableElement;
import electrosphere.renderer.ui.elementtypes.Element;
import electrosphere.renderer.ui.events.Event; import electrosphere.renderer.ui.events.Event;
import electrosphere.renderer.ui.font.Font; import electrosphere.renderer.ui.font.Font;
import org.joml.Vector3f; import org.joml.Vector3f;
@ -127,18 +128,20 @@ public class BitmapCharacter extends StandardElement implements DrawableElement
@Override @Override
public void applyYoga(int parentX, int parentY) { public void applyYoga(int parentX, int parentY) {
//get the values from yoga if(this.yogaNode != Element.NULL_YOGA_ELEMENT){
float leftRaw = Yoga.YGNodeLayoutGetLeft(yogaNode); //get the values from yoga
float topRaw = Yoga.YGNodeLayoutGetTop(yogaNode); float leftRaw = Yoga.YGNodeLayoutGetLeft(yogaNode);
//apply the values to this component float topRaw = Yoga.YGNodeLayoutGetTop(yogaNode);
this.internalPositionX = (int)leftRaw; //apply the values to this component
this.internalPositionY = (int)topRaw; this.internalPositionX = (int)leftRaw;
this.internalWidth = (int)Yoga.YGNodeLayoutGetWidth(yogaNode); this.internalPositionY = (int)topRaw;
this.internalHeight = (int)Yoga.YGNodeLayoutGetHeight(yogaNode); this.internalWidth = (int)Yoga.YGNodeLayoutGetWidth(yogaNode);
//calculate absolute values this.internalHeight = (int)Yoga.YGNodeLayoutGetHeight(yogaNode);
if(!useAbsolutePosition){ //calculate absolute values
this.absoluteX = parentX + internalPositionX; if(!useAbsolutePosition){
this.absoluteY = parentY + internalPositionY; this.absoluteX = parentX + internalPositionX;
this.absoluteY = parentY + internalPositionY;
}
} }
} }

View File

@ -76,7 +76,7 @@ public class Label extends StandardContainerElement implements DrawableElement {
void generateLetters(){ void generateLetters(){
//free children //free children
for(Element child : childList){ for(Element child : childList){
Yoga.YGNodeFree(child.getYogaNode()); child.destroy();
} }
childList.clear(); childList.clear();
int accumulatingWidth = 0; int accumulatingWidth = 0;

View File

@ -238,31 +238,35 @@ public class StandardContainerElement extends StandardElement implements Contain
for(Element child : childList){ for(Element child : childList){
child.destroy(); child.destroy();
} }
Yoga.YGNodeFree(this.yogaNode); if(this.yogaNode != Element.NULL_YOGA_ELEMENT){
Yoga.YGNodeFree(this.yogaNode);
}
} }
@Override @Override
public void applyYoga(int parentX, int parentY) { public void applyYoga(int parentX, int parentY) {
//get the values from yoga if(this.yogaNode != Element.NULL_YOGA_ELEMENT){
float leftRaw = Yoga.YGNodeLayoutGetLeft(yogaNode); //get the values from yoga
float topRaw = Yoga.YGNodeLayoutGetTop(yogaNode); float leftRaw = Yoga.YGNodeLayoutGetLeft(yogaNode);
float widthRaw = Yoga.YGNodeLayoutGetWidth(yogaNode); float topRaw = Yoga.YGNodeLayoutGetTop(yogaNode);
float heightRaw = Yoga.YGNodeLayoutGetHeight(yogaNode); float widthRaw = Yoga.YGNodeLayoutGetWidth(yogaNode);
LoggerInterface.loggerUI.DEBUG("" + this); float heightRaw = Yoga.YGNodeLayoutGetHeight(yogaNode);
LoggerInterface.loggerUI.DEBUG("pos(" + leftRaw + "," + topRaw + ") dim(" + widthRaw + "," + heightRaw + ")"); LoggerInterface.loggerUI.DEBUG("" + this);
//apply the values to this component LoggerInterface.loggerUI.DEBUG("pos(" + leftRaw + "," + topRaw + ") dim(" + widthRaw + "," + heightRaw + ")");
if(!useAbsolutePosition){ //apply the values to this component
this.internalPositionX = (int)leftRaw; if(!useAbsolutePosition){
this.internalPositionY = (int)topRaw; this.internalPositionX = (int)leftRaw;
this.internalWidth = (int)widthRaw; this.internalPositionY = (int)topRaw;
this.internalHeight = (int)heightRaw; this.internalWidth = (int)widthRaw;
//calculate absolute values this.internalHeight = (int)heightRaw;
this.absoluteX = parentX + internalPositionX; //calculate absolute values
this.absoluteY = parentY + internalPositionY; this.absoluteX = parentX + internalPositionX;
} this.absoluteY = parentY + internalPositionY;
//apply yoga values to all children }
for(Element child : this.getChildren()){ //apply yoga values to all children
child.applyYoga(parentX + internalPositionX,parentY + internalPositionY); for(Element child : this.getChildren()){
child.applyYoga(parentX + internalPositionX,parentY + internalPositionY);
}
} }
} }

View File

@ -157,7 +157,10 @@ public class StandardElement implements Element {
@Override @Override
public void destroy(){ public void destroy(){
Yoga.YGNodeFree(this.yogaNode); if(this.yogaNode != Element.NULL_YOGA_ELEMENT){
Yoga.YGNodeFree(this.yogaNode);
this.yogaNode = Element.NULL_YOGA_ELEMENT;
}
} }
@Override @Override
@ -167,20 +170,22 @@ public class StandardElement implements Element {
@Override @Override
public void applyYoga(int parentX, int parentY) { public void applyYoga(int parentX, int parentY) {
//get the values from yoga if(this.yogaNode != Element.NULL_YOGA_ELEMENT){
float leftRaw = Yoga.YGNodeLayoutGetLeft(yogaNode); //get the values from yoga
float topRaw = Yoga.YGNodeLayoutGetTop(yogaNode); float leftRaw = Yoga.YGNodeLayoutGetLeft(yogaNode);
float widthRaw = Yoga.YGNodeLayoutGetWidth(yogaNode); float topRaw = Yoga.YGNodeLayoutGetTop(yogaNode);
float heightRaw = Yoga.YGNodeLayoutGetHeight(yogaNode); float widthRaw = Yoga.YGNodeLayoutGetWidth(yogaNode);
if(!useAbsolutePosition){ float heightRaw = Yoga.YGNodeLayoutGetHeight(yogaNode);
//apply the values to this component if(!useAbsolutePosition){
this.internalPositionX = (int)leftRaw; //apply the values to this component
this.internalPositionY = (int)topRaw; this.internalPositionX = (int)leftRaw;
this.internalWidth = (int)widthRaw; this.internalPositionY = (int)topRaw;
this.internalHeight = (int)heightRaw; this.internalWidth = (int)widthRaw;
//calculate absolute values this.internalHeight = (int)heightRaw;
this.absoluteX = parentX + internalPositionX; //calculate absolute values
this.absoluteY = parentY + internalPositionY; this.absoluteX = parentX + internalPositionX;
this.absoluteY = parentY + internalPositionY;
}
} }
} }

View File

@ -1,7 +1,5 @@
package electrosphere.renderer.ui.elements; package electrosphere.renderer.ui.elements;
import org.lwjgl.util.yoga.Yoga;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.renderer.OpenGLState; import electrosphere.renderer.OpenGLState;
import electrosphere.renderer.RenderPipelineState; import electrosphere.renderer.RenderPipelineState;
@ -110,7 +108,7 @@ public class TextBox extends StandardDrawableContainerElement {
void generateLetters(){ void generateLetters(){
//free children //free children
for(Element child : childList){ for(Element child : childList){
Yoga.YGNodeFree(child.getYogaNode()); child.destroy();
} }
childList.clear(); childList.clear();
String[] words = text.split(" "); String[] words = text.split(" ");

View File

@ -355,24 +355,26 @@ public class Window implements DrawableElement, ContainerElement, NavigableEleme
@Override @Override
public void applyYoga(int parentX, int parentY) { public void applyYoga(int parentX, int parentY) {
Yoga.YGNodeStyleSetWidth(parentWindowYogaNode, Globals.WINDOW_WIDTH); if(this.yogaNode != Element.NULL_YOGA_ELEMENT){
Yoga.YGNodeStyleSetHeight(parentWindowYogaNode, Globals.WINDOW_HEIGHT); Yoga.YGNodeStyleSetWidth(parentWindowYogaNode, Globals.WINDOW_WIDTH);
//calculate yoga layout Yoga.YGNodeStyleSetHeight(parentWindowYogaNode, Globals.WINDOW_HEIGHT);
Yoga.YGNodeCalculateLayout(parentWindowYogaNode, width, height, Yoga.YGDirectionInherit); //calculate yoga layout
//get the values from yoga Yoga.YGNodeCalculateLayout(parentWindowYogaNode, width, height, Yoga.YGDirectionInherit);
float leftRaw = Yoga.YGNodeLayoutGetLeft(yogaNode); //get the values from yoga
float topRaw = Yoga.YGNodeLayoutGetTop(yogaNode); float leftRaw = Yoga.YGNodeLayoutGetLeft(yogaNode);
float widthRaw = Yoga.YGNodeLayoutGetWidth(yogaNode); float topRaw = Yoga.YGNodeLayoutGetTop(yogaNode);
float heightRaw = Yoga.YGNodeLayoutGetHeight(yogaNode); float widthRaw = Yoga.YGNodeLayoutGetWidth(yogaNode);
// //apply the values to this component float heightRaw = Yoga.YGNodeLayoutGetHeight(yogaNode);
this.positionX = (int)leftRaw; // //apply the values to this component
this.positionY = (int)topRaw; this.positionX = (int)leftRaw;
this.width = (int)widthRaw; this.positionY = (int)topRaw;
this.height = (int)heightRaw; this.width = (int)widthRaw;
//apply yoga values to all children this.height = (int)heightRaw;
LoggerInterface.loggerUI.DEBUG("==Apply yoga to windoow=="); //apply yoga values to all children
for(Element child : this.getChildren()){ LoggerInterface.loggerUI.DEBUG("==Apply yoga to windoow==");
child.applyYoga(this.positionX,this.positionY); for(Element child : this.getChildren()){
child.applyYoga(this.positionX,this.positionY);
}
} }
} }

View File

@ -1,7 +1,5 @@
package electrosphere.renderer.ui.elements; package electrosphere.renderer.ui.elements;
import org.lwjgl.util.yoga.Yoga;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
import electrosphere.renderer.OpenGLState; import electrosphere.renderer.OpenGLState;
@ -88,7 +86,7 @@ public class Word extends StandardDrawableContainerElement {
void generateLetters(){ void generateLetters(){
//free children //free children
for(Element child : childList){ for(Element child : childList){
Yoga.YGNodeFree(child.getYogaNode()); child.destroy();
} }
childList.clear(); childList.clear();
for(int i = 0; i < text.length(); i++){ for(int i = 0; i < text.length(); i++){

View File

@ -4,6 +4,11 @@ import electrosphere.renderer.ui.events.Event;
public interface Element { public interface Element {
/**
* A yoga element that either hasn't been created or has already been destroyed
*/
public static final int NULL_YOGA_ELEMENT = -1;
//width and height //width and height
public int getWidth(); public int getWidth();
public int getHeight(); public int getHeight();