subsoap / defos

Extra native OS functions for games written using the Defold game engine
Creative Commons Zero v1.0 Universal
112 stars 16 forks source link

Toggling fullscreen in update() of gui script creates error #91

Closed 8bitskull closed 3 years ago

8bitskull commented 5 years ago

Hi! This is asvegren from the Defold forums.

First of all - massive thanks for this amazing extension.

I have encountered an issue using defos.set_fullscreen(bool_value) and defos.toggle_fullscreen(). I have a gui component that deals with various game settings, including full screen. I noticed that toggling full screen interrups the completion of the rest of the update() cycle in my gui script.

When I click the fullscreen button in my script (which immediately triggers defos.toggle_fullscreen()), the next gui node accessed using gui.get_node() is not found, yielding an error like this: ERROR:SCRIPT: /HUD/settings/settings.gui_script:19: No such node: scaling_bg

scaling_bg in this example isn't actually deleted however.

I've realised that I don't have any issue if I just move my fullscreen toggle check to the end of the update() cycle (thereby not accessing any more gui nodes), however I thought I would raise this just in case it's important for anyone else.

britzl commented 5 years ago

Hmm, that is quite surprising behaviour to be honest! I'm not sure what could be causing it. I guess you could post a message to yourself when you detect the click in on_input() and handle the message in on_message() where you call triggers defos.toggle_fullscreen().

subsoap commented 5 years ago

I agree with @britzl you probably will be able to deal with this best by sending a message to itself or another script to do the toggling on getting the message to avoid any interrupt. But you should also try to make a minimal reproducing example for us to test and see what's really going on.

What OS is this happening on?

8bitskull commented 5 years ago

Thanks for the suggestions on sending messages to shift where the call happens.

I am getting this error on Windows 7.

I tried making a reproducing example, but am failing to do so. The example I am pasting below is indicative of what happens in my main project and should trigger the error, but doesn't. I suppose that means either I'm misunderstanding the cause or there is something else interacting in my main project.


function init(self)
    full_toggled = false
end

function update(self, dt)

    if not full_toggled then

        print("getting:", gui.get_node("box1"))

        defos.toggle_fullscreen()

        full_toggled = true

        print("getting:", gui.get_node("box2"))

    end

end
britzl commented 3 years ago

@8bitskull is this still happening?

8bitskull commented 3 years ago

I reset the offending script to its original configuration and can no longer reproduce the issue.