out-of-memory.html (2161B)
1 <!-- 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. 5 --> 6 7 <!DOCTYPE html> 8 <html> 9 <head> 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> 15 </head> 16 <body> 17 <div id="description"></div> 18 <div id="console"></div> 19 <canvas id="canvas" width="2" height="2"> </canvas> 20 <script> 21 "use strict"; 22 debug("This tests WebGL running out of memory."); 23 24 debug(""); 25 debug("Canvas.getContext"); 26 27 var wtu = WebGLTestUtils; 28 var gl = wtu.create3DContext("canvas"); 29 if (!gl) { 30 testFailed("context does not exist"); 31 } else { 32 testPassed("context exists"); 33 34 debug(""); 35 debug("Allocating shaders."); 36 37 function makeBigShader() { 38 var lines = []; 39 var line = "// "; 40 for (var ii = 0; ii < 1024; ++ii) { 41 line += String.fromCharCode(48 + ii % 10); 42 } 43 for (var ii = 0; ii < 1024; ++ii) { 44 lines[ii] = line; 45 } 46 var oneMB = lines.join(); 47 for (var ii = 0; ii < 64; ++ii) { 48 lines[ii] = oneMB; 49 } 50 return lines.join("\n"); 51 } 52 53 var shaderSource = makeBigShader(); 54 debug("created " + Math.floor(shaderSource.length / 1024 / 1024) + "MB shader"); 55 56 var intervalId; 57 var count = 0; 58 59 function makeShader() { 60 ++count; 61 debug ("creating shader #" + count + " mem = " + Math.floor(shaderSource.length * count / 1024 / 1024) + "MB"); 62 var shader = gl.createShader(gl.VERTEX_SHADER); 63 if (shader == null) { 64 window.clearInterval(intervalId); 65 testPassed("createShader returns null"); // not sure this is a passing 66 finishTest(); 67 } else { 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"); 73 finishTest(); 74 } 75 } 76 } 77 78 intervalId = window.setInterval(makeShader, 1000/15); 79 } 80 </script> 81 <script src="../js/js-test-post.js"></script> 82 83 </body> 84 </html>