Html.run problems (abort() and stop application)


#1

Hello!
I build my Html game into the site and use html5.run. I’m trying to return the data in defold (Json as a string), but the string does not return all and with strange characters at the end.

At the top of the line, which should return, from below, as it takes a defold. I made this line much longer - the result is the same - a few last characters are replaced

lua code

html5.run("callApi('".. self.method.."', { "..self.params_str_html5.." }, "..self.key..");")

    local timer_id = nil
    timer_id = timer.delay(0.1, true, function()
      local response = html5.run("vkCallback("..self.key..")")

      if response ~= '' then
        timer.cancel(timer_id)
        print(response)
        local jd = json.decode(response)
        self.cb(jd.response)
      end
    end)

js code

			var api_responses = [];
			function callApi(method, params, key) {
				VK.api(method, params, function (data) {
					api_responses[key] = JSON.stringify(data);
				});
			}
			function vkCallback(key) {
				var response = '';
				if (api_responses[key]) {
					response = api_responses[key];
					delete api_responses[key];
					console.log(response);
				}
				return response;
			}

If I try to get a string directly, I get an error and the app is stopped

-- lua
local test_resp = html5.run('getStartParameters()')
print(test_resp)

-- js
function getStartParameters() {
     return '[{"id":35917273,"first_name":"Любовь","last_name":"Чижевская","sex":1,"photo_50":"https://pp.userapi.com/c824603/v824603160/145e9d/WF05WuJXMvE.jpg?ava=1","photo_100":"https://pp.userapi.com/c824603/v824603160/145e9c/oa-4TJpv55Q.jpg?ava=1"},{"id":59262819,"first_name":"Витя","last_name":"Гиль","sex":2,"photo_50":"https://pp.userapi.com/c834200/v834200115/1783c4/N5vHRfxXhqM.jpg?ava=1","photo_100":"https://pp.userapi.com/c834200/v834200115/1783c3/gcTnQ0qwRBs.jpg?ava=1"}]';
}

I will be grateful for your advice on solving this problem!

Thank you!


#2

@Mathias_Westerdahl what’s the max length of a response for html5.run?

You mentioned an error as well. What kind of error?


#3

You can make a small native extension to return the data you need from the JS. I think it still has limitations but may not be as small?


#4

Thanks for answers!
Up to 250 characters no error occurs. Now I break the response into 250 characters and glue together before decoding. The problem has disappeared - now everything works well!

There was a message that something like “created crushdump” in data/.defold, I will be glad to give more information if you tell me how I can get it. Thank you!


#5

I’m glad you could work around it.

There’s definitely something weird going on though, and we’ll look into this further.