فهرست منبع

Add type guard around WebGLPipelineContext

Popov72 5 سال پیش
والد
کامیت
b0b84a819a
1فایلهای تغییر یافته به همراه6 افزوده شده و 2 حذف شده
  1. 6 2
      src/Materials/effect.ts

+ 6 - 2
src/Materials/effect.ts

@@ -637,6 +637,10 @@ export class Effect implements IDisposable {
         return [code, errorLine];
         return [code, errorLine];
     }
     }
 
 
+    private _isWebGLPipelineContext(obj: any): obj is WebGLPipelineContext {
+        return obj.vertexShader && obj.fragmentShader;
+    }
+
     private _processCompilationErrors(e: any, previousPipelineContext: Nullable<IPipelineContext> = null) {
     private _processCompilationErrors(e: any, previousPipelineContext: Nullable<IPipelineContext> = null) {
         this._compilationError = e.message;
         this._compilationError = e.message;
         let attributesNames = this._attributesNames;
         let attributesNames = this._attributesNames;
@@ -651,8 +655,8 @@ export class Effect implements IDisposable {
             return " " + attribute;
             return " " + attribute;
         }));
         }));
         Logger.Error("Defines:\r\n" + this.defines);
         Logger.Error("Defines:\r\n" + this.defines);
-        if (Effect.LogShaderCodeOnCompilationError) {
-            let pcw = this._pipelineContext as WebGLPipelineContext;
+        if (Effect.LogShaderCodeOnCompilationError && this._isWebGLPipelineContext(this._pipelineContext)) {
+            let pcw = this._pipelineContext;
             let lineErrorVertex = null, lineErrorFragment = null, code = null;
             let lineErrorVertex = null, lineErrorFragment = null, code = null;
             if (pcw.vertexShader) {
             if (pcw.vertexShader) {
                 [code, lineErrorVertex] = this._getShaderCodeAndErrorLine(pcw.vertexShader, this._compilationError, false);
                 [code, lineErrorVertex] = this._getShaderCodeAndErrorLine(pcw.vertexShader, this._compilationError, false);