Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

calling visualize() after renderloop() #170

Closed
nico202 opened this issue May 5, 2017 · 17 comments
Closed

calling visualize() after renderloop() #170

nico202 opened this issue May 5, 2017 · 17 comments

Comments

@nico202
Copy link

nico202 commented May 5, 2017

Hi, sorry to bother again, but I can't understand a thing.

example code:

function function_that_might_call_visualize_and__view(x)
     if condition_is_true
          el = visualize(things)
          println("called")
          _view(el)
     end
     true
end

foreach(function_that_might_call_visualize_and__view, fps(50))
renderloop(window)

In this trivial example, as soon as condition_is_true, the rendering freezes, and "called" is never printed. However if I call visualize and _view before renderloop, they do work.

How am I supposed to add new elements? I can't find an example doing this

Thanks, Nicolò

@SimonDanisch
Copy link
Member

No worries!
renderloop(window) is blocking!
Try @async renderloop(window)

@nico202
Copy link
Author

nico202 commented May 5, 2017

Yeah I know it's blocking, but the function function_that_might_call_visualize_and__view, since is in a foreach = preserve(map()) get called. Is the fact that it's called that blocks completely the rendering (the scene that was moving, freezes as soon as "condition_is_true" is true).
Indeed, using @async does not help

@SimonDanisch
Copy link
Member

Ah sorry didn't look closely enough... Btw, are you sure that you want to visualize something every 1/50 seconds ??? That's not how GLVisualize is intended to be used.

@SimonDanisch
Copy link
Member

I can reproduce your problem and on first sight it looks like a bug...

@nico202
Copy link
Author

nico202 commented May 5, 2017

@async + yield() did the tricks however, thanks :)

About fps(), 50Hz is approximately the refresh rate of the monitor, so I thought for a "video game" is the right value. Which frame rate would you use? it works well at this value

@SimonDanisch
Copy link
Member

No, that's not what I meant, but _view(visualize) is not an operation you should do every frame.
It creates a new object on the GPU and puts it into a scene, which you then can manipulate. It's quite expensive and will fill up your GPU's memory.

So you should rather do something like this:

x = _view(visualize(...));

function update_loop()
    GLAbstraction.set_arg!(x, :color, newcolor)
end
# or 
color = Signal(color)
x = _view(visualize(..., color = color))
function update_loop()
push!(color, newcolor)
end

@nico202
Copy link
Author

nico202 commented May 5, 2017

But condition_is_true is a keypress, so it's true rarely.
The fact is that I need to add objects, not change properties of an existing one...

However, there is something strange.
The @async + yield works only if I have a println() statement in the function called..

@SimonDanisch
Copy link
Member

Ideally, you can create all objects you want to view upfront and then just manipulate those... But of course you can also dynamically insert/delete objects at runtime, as you can see now that your example is working.
Delete is not documented as far as I know (and not implemented very well as it seems) :

x = visualize(...)
delete!(window, x.children[])

The x.children is because I didn't implement it for my nested visualize objects.
So what I should add is this function:

function Base.delete!(window::Screen, obj::Composable)
for child in obj.children
delete!(window, child)
end
end

@nico202
Copy link
Author

nico202 commented May 5, 2017

My example is not exactly working, just sometimes. I still do not have the behavior I need.

@SimonDanisch
Copy link
Member

well, did you try restructuring your code as I explained?

@nico202
Copy link
Author

nico202 commented May 5, 2017

I'm creating it before with a scale of 0.0 and then pushing to the scale matrix the value 1.0, but I am still not able to dynamically create them

@SimonDanisch SimonDanisch reopened this May 8, 2017
@SimonDanisch
Copy link
Member

After some more investigation, I think this must be a Reactive bug! Will look into it today

@timholy
Copy link
Contributor

timholy commented May 8, 2017

Be sure you test the new Reactive (aka master, not yet tagged), it's a very fundamental rewrite and might already fix the bug.

@SimonDanisch
Copy link
Member

I think it did indeed...needs more testing though

@SimonDanisch
Copy link
Member

I think I found a possible problem on Reactive master...
Since it was spurious, I don't know for sure though -.-
JuliaGizmos/Reactive.jl#137

@nico202
Copy link
Author

nico202 commented May 11, 2017

Cool, thanks for working on this

@SimonDanisch
Copy link
Member

Please try on Reactive master again! A lot of bugs have been fixed ;)

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

No branches or pull requests

3 participants