Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with GLFW #84

Open
Gilga opened this issue Feb 14, 2016 · 4 comments
Open

Problems with GLFW #84

Gilga opened this issue Feb 14, 2016 · 4 comments

Comments

@Gilga
Copy link

Gilga commented Feb 14, 2016

System: Windows 8.1 (x64)
Julia: 0.4.0

when i use GLFW.PollEvents() and sleep(0.01) in a while loop it seems signals are not updated. sometimes it works and sometimes not. (this often happens when i move the glfw window. it just breaks and i get no more updates)

May its a common problem when using GLFW. Is there a workround for it?

I use signals to check a file update, it prints me a msg when i change the file.
Code:

function isUpdated(file::File, updatewhile=Reactive.Signal(true), update_interval=1.0)
    fn = filename(file)
    file_edited = foldp((false, mtime(fn)), fpswhen(updatewhile, 1.0/update_interval)) do v0, v1
        time_edited = mtime(fn)
        (!isapprox(0.0, v0[2] - time_edited), time_edited)
    end
    filter(identity, false, map(first, file_edited))
end

function watchFileUpdate(path::AbstractString, OnUpdate::Function)
    map(isUpdated(query(path))) do _unused
        println("OnUpdate: ", path)
    end
end
@Gilga Gilga changed the title problems with GLFW Problems with GLFW Feb 14, 2016
@SimonDanisch
Copy link
Member

In this minimal example, you should put a preserve in there:

function watchFileUpdate(path::AbstractString, OnUpdate::Function)
    preserve(map(isUpdated(query(path))) do _unused
        println("OnUpdate: ", path)
    end)
end

Otherwise the signal might get garbage collected!

Just to understand you better, is this minimal example only broken together with GLFW?

@SimonDanisch
Copy link
Member

If the latter is the case, how does the while loop look exactly?
If it's really just this:

while !GLFW.WindowShouldClose(window)
GLFW.PollEvents()
sleep(0.01)
end

You would need a yield() in there.

@Gilga
Copy link
Author

Gilga commented Mar 23, 2016

Okey, it was a bit more. I still dont know whats going on. If i use GL functions in the loop it wont update. if i use non-GL functions it may work (sometimes it does and sometimes not). May something is overwritten in RAM? Its really confusing. For a moment i thought it has to do with the focus of the window when i start my program but i couldnt reproduce the problem.
i used glClear here.

while !GLFW.WindowShouldClose(window)
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) #or Dates.time() 
 GLFW.PollEvents()
 yield() # or sleep
end

@Gilga
Copy link
Author

Gilga commented Mar 23, 2016

I dont know if this is the same problem (i dont get errors so far): #88

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants