unrealnl Posted August 23, 2017 Share Posted August 23, 2017 Hey guys, I'm new to this forum! Use to be an oldschool flash developer (erik.newgrounds.com) and am now seriously looking at building games in HTML5. I had zero problems until i opened my game in Firefox (54.0.1 (32-bits), and Pixi v4.5.0..) and it threw the following error: TypeError: resources['assets/images/bodyparts.json'].textures is undefined[Meer info] After digging a bit deeper and logging the above mentioned resource object i see: Object { _flags: 2, name: "assets/images/bodyparts.json", url: "assets/images/bodyparts.json", extension: "json", data: null, crossOrigin: "", loadType: 1, xhrType: "json", metadata: Object, error: Error, nog 17… } When i click the Error message i see the following error:Error trying to parse loaded json: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data I cant find anything wrong with my json, even JSONLint tells me its ok. Also in Chrome everything works perfectly fine. JSON object is attached to this topic. Any idea whats going on here? Thanks for the help! Erik Firefox v bodyparts.json ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted August 23, 2017 Share Posted August 23, 2017 Welcome, fellow Flash-developer! For any html5 engine/rendering_lib if you see a problem with json, regardless of your browser, please look in devtools in "network" tab and analyze the XHR request. In most of cases, its CORS problem, and you can search through this subforum and https://github.com/pixijs/pixi.js/issues , we had a large number of those issues. Quote Link to comment Share on other sites More sharing options...
unrealnl Posted August 23, 2017 Author Share Posted August 23, 2017 Hi Ivan! so the file downloads normally and im not sure what i should look at? Thanks for helping out! Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted August 23, 2017 Share Posted August 23, 2017 You can find "JSON.parse" line of resources-loader in pixi.js and place breakpoint there. Did you search for CORS and firefox issues? I'm sure there was that kind of problem. unrealnl 1 Quote Link to comment Share on other sites More sharing options...
unrealnl Posted August 23, 2017 Author Share Posted August 23, 2017 I couldn't find anything that answers my particular issue with the character being wrong. I did find several cors issues. After some more spitting , when i trace my json text in firefox within pixi.js i see the following characters: Im now looking i can fix my JSON .. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted August 23, 2017 Share Posted August 23, 2017 Looks like UTF-16. Open it with notepad++ and convert to UTF-8. What's your web-server? unrealnl 1 Quote Link to comment Share on other sites More sharing options...
unrealnl Posted August 23, 2017 Author Share Posted August 23, 2017 Hi Ivan, you were right all along.. obviously i never doubted you Im using XAMPP as my local server, and it were indeed CORS issues. Create a file called ".htaccess" in the directory of my files and add the following to the file. Header set Access-Control-Allow-Origin "http://localhost:8080/" Works like a charm now! Thanks again! ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
tywang2006 Posted September 4, 2017 Share Posted September 4, 2017 I bet it was unicode issue. do UTF converting firstly then check no weird charactor code Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.