소스 검색

Fixed some bugs in LoadFile

Two bugs fixed:

**HTTP errors being considered as a successful response**
Success was conditional on HTTP code 200 OR `ValidateXHRData()` returning true. When dataType is 1 (text) ValidateXHRData returns true if the response is a non-empty string. Often the response text will be set to some HTTP status error message (like "404 Not found") when the response fails, causing ValidateXHRData to return true and LoadFile to execute the callback.

I've removed the ValidateXHRData check from LoadFile because more generally we shouldn't want LoadFile to validate the data at all, just load it, then the user of LoadFile can validate anything returned based on their own criteria (e,g. whether or not it's a valid TGA)

I've also allowed it to accept all HTTP success codes (2XX)

**Callback being called twice in rare cases**
onreadystatechanged may be called multiple times with the value 4 (XMLHttpRequest.DONE), https://bugs.chromium.org/p/chromium/issues/detail?id=162837  nullifying it after it occurs once prevents this
George Corney 9 년 전
부모
커밋
759a7e21d0
1개의 변경된 파일5개의 추가작업 그리고 3개의 파일을 삭제
  1. 5 3
      src/Tools/babylon.tools.ts

+ 5 - 3
src/Tools/babylon.tools.ts

@@ -394,8 +394,10 @@
                 request.onprogress = progressCallBack;
 
                 request.onreadystatechange = () => {
-                    if (request.readyState === 4) {
-                        if (request.status === 200 || Tools.ValidateXHRData(request, !useArrayBuffer ? 1 : 6)) {
+                    if (request.readyState === XMLHttpRequest.DONE) {
+                        request.onreadystatechange = null;//some browsers have issues where onreadystatechange can be called multiple times with the same value
+
+                        if (request.status >= 200 && request.status < 300) {
                             callback(!useArrayBuffer ? request.responseText : request.response);
                         } else { // Failed
                             if (onError) {
@@ -1257,4 +1259,4 @@
             }, callback);
         }
     }
-} 
+}