Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allocating more than 64 Mesh objects leads to double free / corruption and core dump #7397

Open
streamsoftdev opened this issue May 15, 2024 · 2 comments

Comments

@streamsoftdev
Copy link

In the provided bare bones application below, the program allocates 64 Mesh objects. When it terminates everything is fine.
However if the num_mesh is set to 65 or more, then upon program termination I receive:

double free or corruption (fasttop)
Aborted (core dumped)

Note that, in my actual program I create thousands of Mesh objects. And they render fine. It is only when the program terminates that the double free or corruption occurs. It does not matter if I call dispose() on the mesh objects or not.

import com.badlogic.gdx.Game;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;

public class DesktopLauncher {
	public static class Barebones extends Game {
		Mesh[] meshes;
		
		@Override
		public void create () {
			int num_mesh=64;
			meshes=new Mesh[num_mesh];
			for(int i=0;i<num_mesh;i++){
				meshes[i]=new Mesh(true,10,10,
				new VertexAttribute(Usage.Position,3,"a_position"),
				new VertexAttribute(Usage.Normal,3,"a_normal"),
				new VertexAttribute(Usage.TextureCoordinates,2,"a_texCoord0"));
			}
		}

		@Override
		public void render () {
			super.render();
		}

		
	}
	public static void main (String[] arg) {
		Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
		config.setWindowedMode(1600, 960);
		config.setResizable(false);
      	        config.useVsync(true);
		config.setForegroundFPS(60);
		config.setTitle("My GDX Game");
		new Lwjgl3Application(new Barebones(), config);
	}
}

Please select the affected platforms

  • [X ] Linux
@tommyettinger
Copy link
Member

It definitely seems like a bug, I just can't reproduce it on Windows 10, with Java 17 or Java 8. Linux could be a completely different can of worms, but I don't have a working Linux machine at this moment.

What Java version were you using when you encountered this? It may have to do with the behavior of finalizers, which is different in Java 8 and lower vs. in Java 9 and higher.

@streamsoftdev
Copy link
Author

/usr/lib/jvm/java-17-openjdk-amd64/bin/java --version
openjdk 17.0.10 2024-01-16
OpenJDK Runtime Environment (build 17.0.10+7-Ubuntu-123.10.1)
OpenJDK 64-Bit Server VM (build 17.0.10+7-Ubuntu-123.10.1, mixed mode, sharing)

In the build.gradle files I noticed sourceCompatibility=1.8 and some other version info from the high level build.gradle:

gdxVersion = '1.12.1'
roboVMVersion = '2.3.20'
box2DLightsVersion = '1.5'
ashleyVersion = '1.7.4'
aiVersion = '1.8.2'
gdxControllersVersion = '2.2.1'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants