gpt4 book ai didi

java - 数组缓冲区对象被禁用

转载 作者:行者123 更新时间:2023-12-01 08:11:24 25 4
gpt4 key购买 nike

我尝试创建 3D 立方体,其中存储有 xpos、ypos、类型和 modelInstance。当我尝试运行该程序时,出现此错误:

Exception in thread "LWJGL Application" org.lwjgl.opengl.OpenGLException: Cannot use offsets when Array Buffer Object is disabled

如何启用它?

这是我收到错误的类:

package com.me.the_unknown;

import java.util.ArrayList;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.materials.Material;
import com.badlogic.gdx.graphics.g3d.materials.TextureAttribute;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;

public class Blocks {

public static ArrayList<Float> blockX = new ArrayList<Float>();
public static ArrayList<Float> blockY = new ArrayList<Float>();
public static ArrayList<Integer> blockType = new ArrayList<Integer>();
public static ArrayList<ModelInstance> blockModelInstance = new ArrayList<ModelInstance>();

public static ModelBatch modelBatch;
private static ModelBuilder modelBuilder;

//Textures
public static Texture stonebrick = new Texture("data/blocks/stonebrick.png");
public static Texture gravel = new Texture("data/blocks/gravel.png");

public static void addBlock(int xpos, int ypos, int type) {
blockX.add((float) xpos * 5);
blockY.add((float) ypos * 5);
blockType.add(type);
updateBlocks();
}

private static void updateBlocks() {
blockModelInstance.clear();

for(int counter = 0; counter < blockX.size(); counter++){
Model model = null;
ModelInstance instance;

if(blockType.get(counter) == 1)
model = modelBuilder.createBox(5f, 5f, 5f, new Material(TextureAttribute.createDiffuse(stonebrick)), Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.Generic);
if(blockType.get(counter) == 2)
model = modelBuilder.createBox(5f, 5f, 5f, new Material(TextureAttribute.createDiffuse(gravel)), Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.Generic);

instance = new ModelInstance(model);
blockModelInstance.add(instance);

model.dispose();
}
}

public static void create() {
modelBuilder = new ModelBuilder();
updateBlocks();
}
}

最佳答案

您正在创建一个模型,然后创建它的模型实例,然后处置该模型,这实际上使模型实例无法使用,因为它依赖于模型。

确保模型的生命周期比依赖于它的模型实例的生命周期长,因为它管理着它们的资源。在您的情况下,ModelInstance 将无效,因为它所依赖的 Mesh 是通过调用 model.dispose() 来处置的,从而导致您收到错误。

还要尽量避免静态,当您的应用关闭然后再次重新启动时,它可能会导致设备出现问题。

关于java - 数组缓冲区对象被禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17005585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com