Skip to content

Commit

Permalink
Merge pull request #5460 from ateshuseyin/replace-deverr-with-check-r…
Browse files Browse the repository at this point in the history
…enderer

Replaces DeveloperErrors with Checks in Renderer folder
  • Loading branch information
bagnell authored Oct 20, 2017
2 parents 5d499c5 + d69ebca commit 5f63315
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 290 deletions.
33 changes: 12 additions & 21 deletions Source/Renderer/Buffer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
define([
'../Core/Check',
'../Core/defaultValue',
'../Core/defined',
'../Core/defineProperties',
Expand All @@ -8,6 +9,7 @@ define([
'../Core/WebGLConstants',
'./BufferUsage'
], function(
Check,
defaultValue,
defined,
defineProperties,
Expand All @@ -25,9 +27,7 @@ define([
options = defaultValue(options, defaultValue.EMPTY_OBJECT);

//>>includeStart('debug', pragmas.debug);
if (!defined(options.context)) {
throw new DeveloperError('options.context is required.');
}
Check.defined('options.context', options.context);

if (!defined(options.typedArray) && !defined(options.sizeInBytes)) {
throw new DeveloperError('Either options.sizeInBytes or options.typedArray is required.');
Expand All @@ -37,8 +37,9 @@ define([
throw new DeveloperError('Cannot pass in both options.sizeInBytes and options.typedArray.');
}

if (defined(options.typedArray) && !(typeof options.typedArray === 'object' && typeof options.typedArray.byteLength === 'number')) {
throw new DeveloperError('options.typedArray must be a typed array');
if (defined(options.typedArray)) {
Check.typeOf.object('options.typedArray', options.typedArray);
Check.typeOf.number('options.typedArray.byteLength', options.typedArray.byteLength);
}

if (!BufferUsage.validate(options.usage)) {
Expand All @@ -58,9 +59,7 @@ define([
}

//>>includeStart('debug', pragmas.debug);
if (sizeInBytes <= 0) {
throw new DeveloperError('Buffer size must be greater than zero.');
}
Check.typeOf.number.greaterThan('sizeInBytes', sizeInBytes, 0);
//>>includeEnd('debug');

var buffer = gl.createBuffer();
Expand Down Expand Up @@ -118,9 +117,7 @@ define([
*/
Buffer.createVertexBuffer = function(options) {
//>>includeStart('debug', pragmas.debug);
if (!defined(options.context)) {
throw new DeveloperError('options.context is required.');
}
Check.defined('options.context', options.context);
//>>includeEnd('debug');

return new Buffer({
Expand Down Expand Up @@ -179,15 +176,13 @@ define([
*/
Buffer.createIndexBuffer = function(options) {
//>>includeStart('debug', pragmas.debug);
if (!defined(options.context)) {
throw new DeveloperError('options.context is required.');
}
Check.defined('options.context', options.context);

if (!IndexDatatype.validate(options.indexDatatype)) {
throw new DeveloperError('Invalid indexDatatype.');
}

if ((options.indexDatatype === IndexDatatype.UNSIGNED_INT) && !options.context.elementIndexUint) {
if (options.indexDatatype === IndexDatatype.UNSIGNED_INT && !options.context.elementIndexUint) {
throw new DeveloperError('IndexDatatype.UNSIGNED_INT requires OES_element_index_uint, which is not supported on this system. Check context.elementIndexUint.');
}
//>>includeEnd('debug');
Expand Down Expand Up @@ -249,12 +244,8 @@ define([
offsetInBytes = defaultValue(offsetInBytes, 0);

//>>includeStart('debug', pragmas.debug);
if (!arrayView) {
throw new DeveloperError('arrayView is required.');
}
if (offsetInBytes + arrayView.byteLength > this._sizeInBytes) {
throw new DeveloperError('This buffer is not large enough.');
}
Check.defined('arrayView', arrayView);
Check.typeOf.number.lessThanOrEquals('offsetInBytes + arrayView.byteLength', offsetInBytes + arrayView.byteLength, this._sizeInBytes);
//>>includeEnd('debug');

var gl = this._gl;
Expand Down
10 changes: 4 additions & 6 deletions Source/Renderer/ComputeEngine.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
define([
'../Core/BoundingRectangle',
'../Core/Check',
'../Core/Color',
'../Core/defined',
'../Core/destroyObject',
Expand All @@ -13,6 +14,7 @@ define([
'./ShaderProgram'
], function(
BoundingRectangle,
Check,
Color,
defined,
destroyObject,
Expand Down Expand Up @@ -75,9 +77,7 @@ define([

ComputeEngine.prototype.execute = function(computeCommand) {
//>>includeStart('debug', pragmas.debug);
if (!defined(computeCommand)) {
throw new DeveloperError('computeCommand is required.');
}
Check.defined('computeCommand', computeCommand);
//>>includeEnd('debug');

// This may modify the command's resources, so do error checking afterwards
Expand All @@ -90,9 +90,7 @@ define([
throw new DeveloperError('computeCommand.fragmentShaderSource or computeCommand.shaderProgram is required.');
}

if (!defined(computeCommand.outputTexture)) {
throw new DeveloperError('computeCommand.outputTexture is required.');
}
Check.defined('computeCommand.outputTexture', computeCommand.outputTexture);
//>>includeEnd('debug');

var outputTexture = computeCommand.outputTexture;
Expand Down
Loading

0 comments on commit 5f63315

Please sign in to comment.