Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Manipulating screen objects from inside a coroutine crashes player/app — Gideros Forum

Manipulating screen objects from inside a coroutine crashes player/app

bowerandybowerandy Guru
edited September 2012 in General questions
The app I'm build is starting to get big enough that I've decided to add unit testing. After a bit of trolling around I've settled on a testing framework called LunaTest (http://silentbicycle.com/projects/lunatest/) which is MIT licensed. I'm not using all the randomizing parameters described on that page - just using it as a replacement for lunit.

So, I've got the basics working but it would be convenient if I could run the tests in a coroutine so that I can launch a scene (say) as part of a test setup and yield to wait for it to become available before continuing with the tests. Unfortunately, I found that running the tests inside coroutine crashes the Gideros player.

At first I thought it might be due to the known issue of coroutines and pcall not playing nicely together(http://lua-users.org/wiki/PcallAndCoroutines). There are apparently solutions to this but, in any case, this is not the immediate problem. I've discovered that the crash occurs if I simply create any Gideros screen objects inside a coroutine. Please try this to see what I mean:
-- main.lua
ExampleScene = Core.class(Sprite)
function ExampleScene:init()
	rect=Shape.new()
	rect:setPosition(application:getContentWidth()/2, application:getContentHeight()/2)
	self:addChild(rect)
	stage:addChild(self)
end
 
local co=coroutine.create(function()
	ExampleScene.new()
	end)
coroutine.resume(co)
Is this a bug and can it be fixed?

Best regards

Comments

  • bowerandybowerandy Guru
    edited September 2012
    Actually, it's even easier to get the crash than that:
    --main.lua
    local co=coroutine.create(function()
    	application:getContentWidth()
    	end)
    coroutine.resume(co)
    The crash is: Exception raised: EXC_BAD_ACCESS (code=1, address=0xc))

    and the stack trace is:
    LuaApplication::orietation() const
    ApplicationBinder::getContentWidth(lua_State*)
  • atilimatilim Maintainer
    definitely this is a bug. now I'm fixing it. thank you @bowerandy.
  • @atilim, groovy, thanks.
    Now if we only had bi-weekly builds? :)
  • atilimatilim Maintainer
    Accepted Answer
    :) after improving gdrbridge, I'll release this version. maybe today, most probably tomorrow.
  • @bowerandy - Resurrecting an old thread here, but I'd love to know more about how you've integrated lunatest with Gideros. I've just started looking at it.
  • @Vramin, actually, I didn't finish off this experiment with LunaTest. I did create an automated test feature using a modified version of my event recording stuff (GitHub BhEventShield) but this was more for testing user interfaces.

    As far as I'm aware, @atilim did fix the issues with coroutines though. I use these extensively in the testing solution I came up with.

    best regards
  • I seem to have it set up right, I can get it to execute tests, but if any assertion fails, the Gideros Player quietly exits.

    For example, if I run it like this:
    module(..., package.seeall)
    function test_testing()
    	assert_false(false, "Fehh, this is supposed to be false");
    end
    The output from this is:
    ---- Testing finished in 0.49 ms, with 1 assertion(s) ----
    1 passed, 0 failed, 0 error(s), 0 skipped.

    However, if I run it like this to force a test failure:
    module(..., package.seeall)
    function test_testing()
    	assert_false(true, "Fehh, this is supposed to be false");
    end
    You would expect this to log the test failure because true will never be false, but instead the player quietly exits and nothing is logged to the console.
  • We must have been typing at the same time. ;)

    I'm trying to get a good unit testing setup before I go too much further with my current project. Thanks for the info. I guess I'll keep looking.

    I'm intrigued by Busted, but I'm still trying to figure out how to fold it into a Gideros-based project.

    The BhEventShield looks interesting and useful, though. Thanks for sharing it. My game is very gesture-based, so this might help in setting up the testing.
Sign In or Register to comment.