基本上,当我在 Android Studio 中使用 OpenGL ES 2.0 开发应用程序时,我遇到了一个我无法解决的大问题,它已经困扰了我大约一个星期。
因此,每当我在内存中加载超过 16 个,可能是 17 个任意大小的纹理,并尝试通过我在 Genymotion 中的模拟器或我的 ASUS 平板电脑以 2D 方式显示它们时,它要么开始显示与我之前不同的图像在该特定索引处绑定(bind),或者根本不显示。然而,如果我通过我的三星 Galaxy S6 运行它,它运行良好。但是,如果我加载 16 个或更少的纹理,它可以在我测试它的所有设备上正常工作,包括模拟器。
这让我尝试了一个小实验,看看它是否会显示每个字母为 16x16 png 的字母图像 a-z,所有这些都在我的可绘制文件夹中。当显示每个字母时,屏幕上的尺寸为 80x80,以便我可以看到它们。所以我试着让它运行“a”到“z”。在模拟器和我的平板电脑上,它只显示“a”到“o”,在“p”应该是的末尾有一个“z”,然后就停在那里。在我的 Samsung Galaxy 上,它实际上显示了“a”到“z”并且做了它应该做的事情。考虑到我将常量中的纹理数设置为 27 或什至更高,这对于为什么它不能在其他设备上正确加载没有任何意义。我希望我能解释我的问题。而且我很确定它们都能够加载超过 16 个纹理,所以我的代码一定有问题。我不会展示整个项目,而是会展示问题可能存在的相关区域。感谢您提供任何帮助,并提前致谢。这是我的代码:
常量:
public class Constants
{
public static final int BYTES_PER_FLOAT = 4;
public static final int POSITION_COMPONENT_COUNT = 4;
public static final int NORMAL_COMPONENT_COUNT = 3;
public static final int COLOR_COMPONENT_COUNT = 4;
public static final int TEXTURE_COORDS_COMPONENT_COUNT = 2;
public static final String A_COLOR = "a_Color";
public static final String A_POSITION = "a_Position";
public static final String A_NORMAL = "a_Normal";
public static final String A_TEXTURECOORDS = "a_TextureCoords";
public static final String U_MVMATRIX = "u_MVMatrix";
public static final String U_MVPMATRIX = "u_MVPMatrix";
public static final String U_TEXTURE_UNIT = "u_Texture_Unit";
public static final String U_LIGHTPOS = "u_LightPos";
public static final String V_COLOR = "v_Color";
public static final String V_POSITION = "v_Position";
public static final String V_NORMAL = "v_Normal";
public static float SCREEN_WIDTH;
public static float SCREEN_HEIGHT;
public static int NUMBER_OF_TEXTURES = 27;
}
纹理.java:
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLUtils;
import static android.opengl.GLES20.*;
public class Texture
{
public static int[] texture;
public static void Load(Context context, int resourceId, int index)
{
//glGenTextures(Constants.NUMBER_OF_TEXTURES, texture, starting_index);
//int n: specifies the number of texture names to be generated
//int[] textures: specifies an array in which the generated texture names are stored
//int offset: the starting index of your array!
Bitmap bitmap;
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
// loading texture
bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
// ...and bind it to our array
glActiveTexture(GL_TEXTURE0 + index);
glBindTexture(GL_TEXTURE_2D, texture[index]);
// create nearest filtered texture
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Use Android GLUtils to specify a two-dimensional texture image from our bitmap
GLUtils.texImage2D(GL_TEXTURE_2D, 0, bitmap, 0);
// Clean up
bitmap.recycle();
}
public static void Delete(int[] texture, int starting_index)
{
try
{
glDeleteTextures(1, texture, starting_index);
}
catch(Exception e)
{
return;
}
}
}
Quad.java
import static android.opengl.GLES20.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
public class Quad
{
public float vertices[];
public float colors[];
public float texture_coords[];
public FloatBuffer vertexBuffer;
public FloatBuffer textureBuffer;
public FloatBuffer colorBuffer;
public Quad(float x1, float y1, float z1, float w1,
float x2, float y2, float z2, float w2,
float x3, float y3, float z3, float w3,
float x4, float y4, float z4, float w4,
float red, float green, float blue, float alpha,
float u1, float v1, float u2, float v2)
{
vertices = new float[]{x1, y1, z1, w1,
x2, y2, z2, w2,
x3, y3, z3, w3,
x4, y4, z4, w4};
colors = new float[]{red, green, blue, alpha,
red, green, blue, alpha,
red, green, blue, alpha,
red, green, blue, alpha};
ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(vertices.length * Constants.BYTES_PER_FLOAT);
vertexByteBuffer.order(ByteOrder.nativeOrder());
vertexBuffer = vertexByteBuffer.asFloatBuffer();
vertexBuffer.put(vertices);
vertexBuffer.position(0);
ByteBuffer colorByteBuffer = ByteBuffer.allocateDirect(colors.length * Constants.BYTES_PER_FLOAT);
colorByteBuffer.order(ByteOrder.nativeOrder());
colorBuffer = colorByteBuffer.asFloatBuffer();
colorBuffer.put(colors);
colorBuffer.position(0);
texture_coords = new float[]{u1, v1,
u2, v1,
u1, v2,
u2, v2};
ByteBuffer textureByteBuffer = ByteBuffer.allocateDirect(texture_coords.length * Constants.BYTES_PER_FLOAT);
textureByteBuffer.order(ByteOrder.nativeOrder());
textureBuffer = textureByteBuffer.asFloatBuffer();
textureBuffer.put(texture_coords);
textureBuffer.position(0);
}
public void Draw_Polygon(int index, int program, float[] modelview_projection_matrix, float[] modelview_matrix)
{
int aPositionHandle = glGetAttribLocation(program, Constants.A_POSITION);
glEnableVertexAttribArray(aPositionHandle);
glVertexAttribPointer(aPositionHandle, Constants.POSITION_COMPONENT_COUNT, GL_FLOAT, false, 0, vertexBuffer);
int aColorHandle = glGetAttribLocation(program, Constants.A_COLOR);
glEnableVertexAttribArray(aColorHandle);
glVertexAttribPointer(aColorHandle, Constants.COLOR_COMPONENT_COUNT, GL_FLOAT, false, 0, colorBuffer);
int aTextureCoordsHandle = glGetAttribLocation(program, Constants.A_TEXTURECOORDS);
glEnableVertexAttribArray(aTextureCoordsHandle);
glVertexAttribPointer(aTextureCoordsHandle, Constants.TEXTURE_COORDS_COMPONENT_COUNT, GL_FLOAT, false, 0, textureBuffer);
int uModelViewProjectionMatrixHandle = glGetUniformLocation(program, Constants.U_MVPMATRIX);
glUniformMatrix4fv(uModelViewProjectionMatrixHandle, 1, false, modelview_projection_matrix, 0);
int uModelViewMatrixHandle = glGetUniformLocation(program, Constants.U_MVMATRIX);
glUniformMatrix4fv(uModelViewMatrixHandle, 1, false, modelview_matrix, 0);
int uTextureUnit = glGetUniformLocation(program, Constants.U_TEXTURE_UNIT);
glUniform1i(uTextureUnit, index);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableVertexAttribArray(aPositionHandle);
glDisableVertexAttribArray(aColorHandle);
glDisableVertexAttribArray(aTextureCoordsHandle);
}
}
文本.java:
import android.opengl.Matrix;
import static android.opengl.GLES20.*;
public class Text
{
public Quad[] poly = new Quad[1];
public String string;
public int char_width;
public int char_height;
void Draw()
{
int texture_num = 0;
int x_pos = 0;
int y_pos = 0;
for (int i = 0; i < string.length(); i++)
{
char character = string.charAt(i);
switch(character)
{
case ' ':
{
texture_num = 0;
break;
}
case 'a':
{
texture_num = 1;
break;
}
case 'b':
{
texture_num = 2;
break;
}
case 'c':
{
texture_num = 3;
break;
}
case 'd':
{
texture_num = 4;
break;
}
case 'e':
{
texture_num = 5;
break;
}
case 'f':
{
texture_num = 6;
break;
}
case 'g':
{
texture_num = 7;
break;
}
case 'h':
{
texture_num = 8;
break;
}
case 'i':
{
texture_num = 9;
break;
}
case 'j':
{
texture_num = 10;
break;
}
case 'k':
{
texture_num = 11;
break;
}
case 'l':
{
texture_num = 12;
break;
}
case 'm':
{
texture_num = 13;
break;
}
case 'n':
{
texture_num = 14;
break;
}
case 'o':
{
texture_num = 15;
break;
}
case 'p':
{
texture_num = 16;
break;
}
case 'q':
{
texture_num = 17;
break;
}
case 'r':
{
texture_num = 18;
break;
}
case 's':
{
texture_num = 19;
break;
}
case 't':
{
texture_num = 20;
break;
}
case 'u':
{
texture_num = 21;
break;
}
case 'v':
{
texture_num = 22;
break;
}
case 'w':
{
texture_num = 23;
break;
}
case 'x':
{
texture_num = 24;
break;
}
case 'y':
{
texture_num = 25;
break;
}
case 'z':
{
texture_num = 26;
break;
}
}
Matrix.setIdentityM(OpenGL.model_matrix, 0);
Matrix.translateM(OpenGL.model_matrix, 0, OpenGL.model_matrix, 0, 0.0f, 0.0f, 0.0f);
Matrix.multiplyMM(OpenGL.matrix_ortho_projection_and_view, 0, OpenGL.matrix_ortho_projection, 0, OpenGL.model_matrix, 0);
glUseProgram(Shader.textured_colored_shader_program);
poly[0] = new Quad(x_pos + 0.0f, y_pos + 0.0f, 0.0f, 1.0f,
x_pos + char_width, y_pos + 0.0f, 0.0f, 1.0f,
x_pos + 0.0f, y_pos + char_height, 0.0f, 1.0f,
x_pos + char_width, y_pos + char_height, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f);
poly[0].Draw_Polygon(texture_num, Shader.textured_colored_shader_program, OpenGL.matrix_ortho_projection_and_view, OpenGL.model_matrix);
x_pos += char_width;
if (x_pos >= Constants.SCREEN_WIDTH)
{
x_pos = 0;
y_pos += char_height;
}
}
}
}
OpenGL.java:
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.content.Context;
import android.opengl.GLSurfaceView.Renderer;
import static android.opengl.GLES20.*;
import android.util.Log;
import android.opengl.Matrix;
public class OpenGL implements Renderer
{
public static Context context;
public static final float[] matrix_ortho_projection = new float[16];
public static float[] model_matrix = new float[16];
private final float[] matrix_view = new float[16];
public static final float[] matrix_ortho_projection_and_view = new float[16];
public int get_width, get_height;
public static boolean texture_loading_enabled = true;
Text text = new Text();
public OpenGL(Context context)
{
this.context = context;
}
public static void Load_Textures()
{
switch(State.game_state)
{
case State.LOGO:
{
Texture.Delete(Texture.texture, 0);
glFlush();
Texture.texture = new int[Constants.NUMBER_OF_TEXTURES];
glGenTextures(Constants.NUMBER_OF_TEXTURES, Texture.texture, 0);
Texture.Load(context, R.drawable.c64_space, 0);
Texture.Load(context, R.drawable.c64_a, 1);
Texture.Load(context, R.drawable.c64_b, 2);
Texture.Load(context, R.drawable.c64_c, 3);
Texture.Load(context, R.drawable.c64_d, 4);
Texture.Load(context, R.drawable.c64_e, 5);
Texture.Load(context, R.drawable.c64_f, 6);
Texture.Load(context, R.drawable.c64_g, 7);
Texture.Load(context, R.drawable.c64_h, 8);
Texture.Load(context, R.drawable.c64_i, 9);
Texture.Load(context, R.drawable.c64_j, 10);
Texture.Load(context, R.drawable.c64_k, 11);
Texture.Load(context, R.drawable.c64_l, 12);
Texture.Load(context, R.drawable.c64_m, 13);
Texture.Load(context, R.drawable.c64_n, 14);
Texture.Load(context, R.drawable.c64_o, 15);
Texture.Load(context, R.drawable.c64_p, 16);
Texture.Load(context, R.drawable.c64_q, 17);
Texture.Load(context, R.drawable.c64_r, 18);
Texture.Load(context, R.drawable.c64_s, 19);
Texture.Load(context, R.drawable.c64_t, 20);
Texture.Load(context, R.drawable.c64_u, 21);
Texture.Load(context, R.drawable.c64_v, 22);
Texture.Load(context, R.drawable.c64_w, 23);
Texture.Load(context, R.drawable.c64_x, 24);
Texture.Load(context, R.drawable.c64_y, 25);
Texture.Load(context, R.drawable.c64_z, 26);
break;
}
case State.TITLE:
{
break;
}
case State.GAME:
{
break;
}
}
texture_loading_enabled = false;
}
private void Controls()
{
switch(State.game_state)
{
case State.LOGO:
{
break;
}
case State.TITLE:
{
break;
}
case State.GAME:
{
break;
}
}
}
@Override
public void onDrawFrame(GL10 glUnused)
{
Controls();
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
switch(State.game_state)
{
case State.LOGO:
{
text.Draw();
break;
}
case State.TITLE:
{
break;
}
case State.GAME:
{
break;
}
}
}
@Override
public void onSurfaceChanged(GL10 glUnused, int width, int height)
{
// Set the OpenGL viewport to the same size as the surface.
Log.d("TAG", "onSurfaceChanged()");
get_width = width;
get_height = height;
glViewport(0, 0, width, height);
for(int i = 0; i < 16; i++)
{
matrix_ortho_projection[i] = 0.0f;
matrix_view[i] = 0.0f;
model_matrix[i] = 0.0f;
matrix_ortho_projection_and_view[i] = 0.0f;
}
Matrix.orthoM(matrix_ortho_projection, 0, 0.0f, (float) get_width, (float) get_height, 0.0f, 0.0f, 1.0f);
}
@Override
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
{
Log.d("TAG", "onSurfaceCreated()");
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
Shader.Create_Texture_Colored_Shader(context);
Shader.Create_Colored_Shader(context);
text.char_width = 80;
text.char_height = 80;
text.string = "abcdefghijklmnopqrstuvwxyz";
switch(State.game_state)
{
case State.LOGO:
{
if (texture_loading_enabled == true)
Load_Textures();
break;
}
case State.TITLE:
{
break;
}
case State.GAME:
{
break;
}
}
}
}
着色器.java:
import android.content.Context;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import static android.opengl.GLES20.*;
public class Shader
{
public static int textured_colored_shader_program;
public static int colored_shader_program;
public static String readTextFileFromRawResource(final Context context, final int resourceId)
{
final InputStream inputStream = context.getResources().openRawResource(resourceId);
final InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
final BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String nextLine;
final StringBuilder body = new StringBuilder();
try
{
while ((nextLine = bufferedReader.readLine()) != null)
{
body.append(nextLine);
body.append('\n');
}
}
catch (IOException e)
{
return null;
}
return body.toString();
}
public static int loadShader(int type, String shaderCode)
{
int shader = glCreateShader(type);
glShaderSource(shader, shaderCode);
glCompileShader(shader);
return shader;
}
public static void Create_Texture_Colored_Shader(Context context)
{
int vertexShader = loadShader(GL_VERTEX_SHADER, readTextFileFromRawResource(context, R.raw.vertex_shader));
int fragmentShader = loadShader(GL_FRAGMENT_SHADER, readTextFileFromRawResource(context, R.raw.fragment_shader));
textured_colored_shader_program = glCreateProgram();
glAttachShader(textured_colored_shader_program, vertexShader);
glAttachShader(textured_colored_shader_program, fragmentShader);
glLinkProgram(textured_colored_shader_program);
}
public static void Create_Colored_Shader(Context context)
{
int vertexShader = loadShader(GL_VERTEX_SHADER, readTextFileFromRawResource(context, R.raw.vertex_shader_no_texture));
int fragmentShader = loadShader(GL_FRAGMENT_SHADER, readTextFileFromRawResource(context, R.raw.fragment_shader_no_texture));
colored_shader_program = glCreateProgram();
glAttachShader(colored_shader_program, vertexShader);
glAttachShader(colored_shader_program, fragmentShader);
glLinkProgram(colored_shader_program);
}
}
最佳答案
纹理对象的总数通常不受限制。至少不在任何合理的范围内,理论上您将运行可以在某个时候由 GLuint 表示的 id。但是在这种情况发生之前很久你就会用完内存。因此,唯一的实际限制通常由用于纹理数据的内存量决定。
然而,纹理单元的数量非常有限。快速查看您的代码,这就是您遇到的问题。从你的纹理加载代码:
glActiveTexture(GL_TEXTURE0 + index);
glBindTexture(GL_TEXTURE_2D, texture[index]);
您要做的是保持所有纹理的绑定(bind),为每个纹理使用不同的纹理单元。然后在绘制时,选择着色器从哪个纹理单元采样:
glUniform1i(uTextureUnit, index);
这是一种完全有效的方法……直到您用完纹理单元。这正是发生的事情。
纹理单元的最大数量取决于实现,可以通过以下方式查询:
GLint maxUnits = 0;
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxUnits);
此值的最小值是 8。因此,除非您检查该值并找到更多值,否则您只能依赖 8 个纹理单元。
如果您需要 8 个以上的纹理,并希望您的代码能够跨设备可靠地运行,那么保持所有纹理绑定(bind)的有点非常规的方法将行不通。
最简单的方法是做大多数人所做的事情:在绘制之前绑定(bind)要使用的纹理。为此,您始终可以使用纹理单元 0。因此,您可以删除对 glActiveTexture() 的所有调用,而只需在 Draw_Polygon() 方法中放置一个绑定(bind)调用,而不是glUniform1i() 调用:
glBindTexture(GL_TEXTURE_2D, texture[index]);
关于java - Android OpenGL ES 2.0 只限于内存中的 16 个纹理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35308057/
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我注意到像bundler这样的项目在每个specfile中执行requirespec_helper我还注意到rspec使用选项--require,它允许您在引导rspec时要求一个文件。您还可以将其添加到.rspec文件中,因此只要您运行不带参数的rspec就会添加它。使用上述方法有什么缺点可以解释为什么像bundler这样的项目选择在每个规范文件中都需要spec_helper吗? 最佳答案 我不在Bundler上工作,所以我不能直接谈论他们的做法。并非所有项目都checkin.rspec文件。原因是这个文件,通常按照当前的惯例,只
我正在使用active_admin,我在Rails3应用程序的应用程序中有一个目录管理,其中包含模型和页面的声明。时不时地我也有一个类,当那个类有一个常量时,就像这样:classFooBAR="bar"end然后,我在每个必须在我的Rails应用程序中重新加载一些代码的请求中收到此警告:/Users/pupeno/helloworld/app/admin/billing.rb:12:warning:alreadyinitializedconstantBAR知道发生了什么以及如何避免这些警告吗? 最佳答案 在纯Ruby中:classA