gpt4 book ai didi

ios - iOS 是否存在导致应用程序崩溃的内存限制?

转载 作者:行者123 更新时间:2023-11-29 12:57:46 25 4
gpt4 key购买 nike

我的应用程序在启动后立即崩溃。我认为这与我在这个 init 函数中定义了两个大数组有关:

- (AppIndex*)init {
if (self = [super init]) {
float rgba[] = { 1.0f, 1.0f, 1.0f, 1.0f };
range = [Text make:@"50 mi" font:[UIFont fontWithName:@"GillSans" size:30] color:rgba width:1000];
[range centerOnX:420 Y:10 width:121 height:40];
mode = [Text make:@"Relevant" font:[UIFont fontWithName:@"GillSans" size:30] color:rgba width:1000];
[mode centerOnX:100 Y:10 width:121 height:40];
NSString* wow = @"WOW";
Vertex vertices[] = {
// Bottom bar
{{640, 0}, {250, 166, 104, 127}},
{{640, 60}, {250, 166, 104, 127}},
{{0, 60}, {250, 166, 104, 127}},
{{0, 0}, {250, 166, 104, 127}},

// Top bar
{{640, [OpenGLView screenHeight] - 60}, {250, 166, 104, 127}},
{{640, [OpenGLView screenHeight]}, {250, 166, 104, 127}},
{{0, [OpenGLView screenHeight]}, {250, 166, 104, 127}},
{{0, [OpenGLView screenHeight] - 60}, {250, 166, 104, 127}},

// Background
{{640, 0}, {255, 255, 255, 0}, {0, 0}},
{{640, [OpenGLView screenHeight]}, {255, 255, 255, 0}, {0, [OpenGLView screenHeight] / 16.0f}},
{{0, [OpenGLView screenHeight]}, {255, 255, 255, 0}, {[OpenGLView screenWidth] / 16.0f, [OpenGLView screenHeight] / 16.0f}},
{{0, 0}, {255, 255, 255, 0}, {[OpenGLView screenWidth] / 16.0f, 0}},

// Icons
{{50, 7}, {255, 255, 255, 0}, {C(294), C(45)}},
{{50, 52}, {255, 255, 255, 0}, {C(294), 0}},
{{7, 52}, {255, 255, 255, 0}, {C(337), 0}},
{{7, 7}, {255, 255, 255, 0}, {C(337), C(45)}},

{{259, 8}, {255, 255, 255, 0}, {C(121), C(40)}},
{{380, 8}, {255, 255, 255, 0}, {C(242), C(40)}},
{{259, 48}, {255, 255, 255, 0}, {C(121), 0}},
{{380, 48}, {255, 255, 255, 0}, {C(242), 0}},

{{585, 11}, {255, 255, 255, 0}, {C(244), C(40)}},
{{633, 11}, {255, 255, 255, 0}, {C(292), C(40)}},
{{585, 51}, {255, 255, 255, 0}, {C(244), 0}},
{{633, 51}, {255, 255, 255, 0}, {C(292), 0}},

{{100, 10}, {255, 255, 255, 0}, {0, C(40)}},
{{221, 10}, {255, 255, 255, 0}, {C(121), C(40)}},
{{100, 50}, {255, 255, 255, 0}, {0, 0}},
{{221, 50}, {255, 255, 255, 0}, {C(121), 0}},

{{420, 10}, {255, 255, 255, 0}, {0, C(40)}},
{{541, 10}, {255, 255, 255, 0}, {C(121), C(40)}},
{{420, 50}, {255, 255, 255, 0}, {0, 0}},
{{541, 50}, {255, 255, 255, 0}, {C(121), 0}},

{{[range X], [range Y]}, {255, 255, 255, 0}, {0, [range TY]}},
{{[range X2], [range Y]}, {255, 255, 255, 0}, {[range TX], [range TY]}},
{{[range X], [range Y2]}, {255, 255, 255, 0}, {0, 0}},
{{[range X2], [range Y2]}, {255, 255, 255, 0}, {[range TX], 0}},

{{[mode X], [mode Y]}, {255, 255, 255, 0}, {0, [mode TY]}},
{{[mode X2], [mode Y]}, {255, 255, 255, 0}, {[mode TX], [mode TY]}},
{{[mode X], [mode Y2]}, {255, 255, 255, 0}, {0, 0}},
{{[mode X2], [mode Y2]}, {255, 255, 255, 0}, {[mode TX], 0}}
};
GLuint vertexSize = 40;
for (size_t i = 0; i < vertexSize; i++) {
vertices[i].position[0] = X(vertices[i].position[0]);
vertices[i].position[1] = Y(vertices[i].position[1], [OpenGLView screenHeight]);
}
GLushort indices[] = {
0, 1, 2,
2, 3, 0,

4, 5, 6,
6, 7, 4,

8, 9, 10,
10, 11, 8,

12, 13, 14,
14, 15, 12,

16, 17, 19,
16, 19, 18,

20, 21, 23,
20, 23, 22,

24, 25, 27,
24, 27, 26,

28, 29, 31,
28, 31, 30,

32, 33, 35,
32, 35, 34,

36, 37, 39,
36, 39, 38
};
GLuint indexSize = 60;
icons = [OpenGLView setupTexture:@"icons.png"];
background = [OpenGLView setupTexture:@"tile.png"];
[self vboWithVertices:vertices count:vertexSize indices:indices count:indexSize];
}
return self;
}

- (void)vboWithVertices:(Vertex[])vertices count:(GLuint)countV indices:(GLushort[])indices count:(GLuint)countI {
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
NSLog(@"%u", sizeof(Vertex));
glBufferData(GL_ARRAY_BUFFER, countV * sizeof(Vertex), vertices, GL_STATIC_DRAW);
glGenBuffers(1, &indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, countI * sizeof(GLushort), indices, GL_STATIC_DRAW);
}

这会做一些事情。 rangemode 是正在加载的两个纹理。 图标背景也是如此。这些巨大的数组最后也被复制到一个 VBO。

这达到了我可以向我的应用程序中添加内容的某个点。现在,如果我向同一个函数添加一行,它就会崩溃。甚至像这样:

NSString* wow = @"Wow";

如果我用数组在函数外添加行,它不会崩溃(大概是因为一些内存已被释放)。

我的应用程序将因 EXC_BAD_ACCESS 而崩溃。如果我注释掉两个大数组,我的应用程序可以运行,所以我认为这是一个内存问题。但是甚至没有使用那么多内存。当应用程序崩溃时,Xcode 表示它运行了 < 1 毫秒并且内存有 6.4MB 的高位和 6.4MB 的低位。

无论如何,这些数组只是占位符,我会更有条理。有补救办法吗?有人可以解释为什么它会崩溃吗?

最佳答案

数组数据都在栈上AFAICS...不要把它放在栈上

关于ios - iOS 是否存在导致应用程序崩溃的内存限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20610569/

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