2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <meta charset=
"utf-8">
11 <title>WebGL Out Of Memory Test
</title>
12 <link rel=
"stylesheet" href=
"../resources/js-test-style.css"/>
13 <script src=
"../js/js-test-pre.js"></script>
14 <script src=
"../js/webgl-test-utils.js"></script>
17 <div id=
"description"></div>
18 <div id=
"console"></div>
19 <canvas id=
"canvas" width=
"2" height=
"2"> </canvas>
22 debug("This tests WebGL running out of memory.");
25 debug("Canvas.getContext");
27 var wtu
= WebGLTestUtils
;
28 var gl
= wtu
.create3DContext("canvas");
30 testFailed("context does not exist");
32 testPassed("context exists");
35 debug("Allocating shaders.");
37 function makeBigShader() {
40 for (var ii
= 0; ii
< 1024; ++ii
) {
41 line
+= String
.fromCharCode(48 + ii
% 10);
43 for (var ii
= 0; ii
< 1024; ++ii
) {
46 var oneMB
= lines
.join();
47 for (var ii
= 0; ii
< 64; ++ii
) {
50 return lines
.join("\n");
53 var shaderSource
= makeBigShader();
54 debug("created " + Math
.floor(shaderSource
.length
/ 1024 / 1024) + "MB shader");
59 function makeShader() {
61 debug ("creating shader #" + count
+ " mem = " + Math
.floor(shaderSource
.length
* count
/ 1024 / 1024) + "MB");
62 var shader
= gl
.createShader(gl
.VERTEX_SHADER
);
64 window
.clearInterval(intervalId
);
65 testPassed("createShader returns null"); // not sure this is a passing
68 gl
.shaderSource(shader
, shaderSource
);
69 var err
= gl
.getError();
70 if (err
!= gl
.NO_ERROR
) {
71 window
.clearInterval(intervalId
);
72 assertMsg(err
== gl
.OUT_OF_MEMORY
, "shaderSource returns OUT_OF_MEMORY");
78 intervalId
= window
.setInterval(makeShader
, 1000/15);
81 <script src=
"../js/js-test-post.js"></script>