我GLSurfaceView在我的应用程序中使用,最近在调整它的大小时发现了一个奇怪的行为。最后,我找出了导致我的应用程序出现问题的原因,并创建了一个简单的示例来重现它。
假设我们有一个FrameLayout包含 simple GLSurfaceView. 在每次点击时,GLSurfaceView我们使用以下代码更改其高度
CyclicIterator<Integer> iterator = CyclicIterator.from(200, 300, 500);
glView.setOnClickListener(v -> {
glView.getLayoutParams().height = sizeIterator.next();
glView.requestLayout();
});
Run Code Online (Sandbox Code Playgroud)
一切顺利,直到我们在后台快速移动应用程序,然后使用“概览”按钮(类似于“猴子测试”)返回到前台。如果我们足够快地在背景/前景之间切换并再次调整视图大小,我们最终可能会遇到以下情况:表面内出现一个“死”区域,直到我们再次停止/开始活动它才会更新。
我glGetError在每次 gl 调用后都检查过,没有收到任何错误。同时我收到了正确的width和height在onSurfaceChanged回调。
我尝试重现此行为并在 Nexus 5X 和小米红米 6A 上获得相同的结果。
GLSurfaceView 配置为:
glView.setEGLContextClientVersion(2);
glView.setRenderer(new Renderer() {
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
}
@Override …Run Code Online (Sandbox Code Playgroud) 我在用vector练习,我想push_back();用for循环来push一个元素,但是程序连for循环都进不去,求救!!!
#include <iostream>
#include <vector>
using namespace std;
int main()
{
cout << "check ";
int val;
vector<char> vec;
cout << "check " << endl << "Its in the game";
//those two "check" were to confirm if the program is even running and is it a
problem while declaring the vector
for(int i = 0; i < vec.size(); i++){
cout << "enter element for vector" << endl;
cin >> val;
vec.push_back(val);
}
}
Run Code Online (Sandbox Code Playgroud)