Pārlūkot izejas kodu

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 gadi atpakaļ
vecāks
revīzija
759a7e21d0
1 mainītis faili ar 5 papildinājumiem un 3 dzēšanām
  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);
         }
     }
-} 
+}