Surface bug or my bad ?

Started by Yosha, March 24, 2015, 09:02:41 AM

Previous topic - Next topic
Hello ! I'm new in the forum, but I know Solarus for a long time. I didn't want to doing some stuff with it before the quest editor was fully operationnal in my opinion, but with the 1.3 version in soon the 1.4, it seems to be the good moment to start it.
Well, I just start two or three weeks ago and for the moment I'm just trying to do some scripting to understand the engine. First of all, I made a night and day cycle and it seems to work. After that, I wanted to do a weather effect with clouds, rain and more, and here is the problem ! I saw in this forum how to show an overlay, but not to make an animation with it. So I coded a script in a map (what I think to be good) but I have an error message and the engine crash after a few moment (2 or 3 minutes or more). I don't know why but the engine crash and I would like to know why !!
Here is the first dialog box message :

Failed to convert software

and the second :

This application has requested the Runtime it in an unusual way. Please contact the application's support team for more information.

I saw that this problem appears only when the surface is animated or moved but not always. Did I do something wrong ?
Here is a shorter and simplified version of what I do (I test it many times and it bug only two times, but it bugged !) :

local map = ...
local Meteo_Pluie_Anim = 1
local Meteo_Etat = "pluie"
local Calque_Pluie = sol.surface.create()

local function Anim()
   Meteo_Pluie_Anim = Meteo_Pluie_Anim + 1
   if Meteo_Pluie_Anim == 4 then Meteo_Pluie_Anim = 1 end   
   Calque_Pluie = sol.surface.create("meteo/"..Meteo_Etat.."_"..Meteo_Pluie_Anim..".png")
end

sol.timer.start(map, 100, function() Anim() return true end)

function map:on_draw(dst_surface)   
   Calque_Pluie:draw(dst_surface)
end

I have other questions, but I will post them in the devlopment section. And sorry for my english...

March 24, 2015, 10:14:47 AM #1 Last Edit: March 24, 2015, 02:01:47 PM by Christopho
Hi,
The "Failed to convert software surface" is an internal bug of the engine. Could you report it on https://github.com/christopho/solarus/issues/new please?

Anyway, you should not create a new surface in the Anim() function because you are doing it every 100 ms. There is no need to repeatedly load the same 3 PNG images over and over again. So you can put them in a local variable outside the function (even if it does not explain the crash, I think):

local Calques_Pluie = {
  sol.surface.create("meteo/pluie_1.png"),
  sol.surface.create("meteo/pluie_2.png"),
  sol.surface.create("meteo/pluie_3.png")
}

and in map:on_draw(), replace Calque_Pluie by Calques_Pluie[Meteo_Pluie_Anim].

Another small detail: if you return true at the end of the Anim() function,

sol.timer.start(map, 100, function() Anim() return true end)

can be replace by simply

sol.timer.start(map, 100, Anim)

March 24, 2015, 12:40:51 PM #2 Last Edit: March 24, 2015, 01:32:06 PM by Yosha
Hi, and thanks for the quick answer !There's a 404 error in your github link, (and anyway I don't know how github works !:p). I was wondering why my game slowed down after the call of the weather function (which is really more important that the part of the code I posted here) and I know why now ! Maybe I should send you the entire script... But I want (or at least try) to find it by myself before ! See you in the dev section !

Sorry but it doesn't work ... Error: Failed to load script 'maps/16': [string "maps/16.lua"]:7: '}' expected (to close '{' at line 5) near 'sol'
Error: In maps/16: attempt to call a string value

I just fixed the code sample and the link.

Thank you ! I tried everything except comma.... :$