keijiro / KlakSpout

Spout plugin for Unity
The Unlicense
673 stars 101 forks source link

Flicker in spout receiver #37

Closed cloaking3000 closed 4 years ago

cloaking3000 commented 5 years ago

I am using Resolume 6 to send video onto geometry using spout receiver and it is strobing inside unity. I thought was an issue with HDRP but also getting in standard. Any ideas how to fix this? Also it used to work, I am currently using unity 2018.3.of2

Thanks so much (:

keijiro commented 5 years ago

Please check if it reproduces with a simple project, like the sample scene in this repository.

cloaking3000 commented 5 years ago

I've tested it in a basic startup 3d project with no additions besides spout. I have installed a few different version of unity and the issue persists, however I can't find sample scene in the project

cloaking3000 commented 5 years ago

I tried installing resolume and unity on a new computer and the issue is still there. I tried disabling v-sync and a few other graphics and changing the frame rate etc

Esam-Bustaty commented 5 years ago

I had (probably) the same problem and I think I got it.

To reproduce all you need is a receiver with targetRenderer but WITHOUT targetTexture.

I tested on Unity 2018.2 and 2019.1, it happened only on 2019.1.

A warning is logged a lot saying Releasing render texture that is set to be RenderTexture.active!.

I found 2 workarounds: Either change this line (looks familiar? ;) to Util.Destroy(_receivedTexture); _receivedTexture = null;

Or delete lines 16-18 in Utility.cs so that Utils.Destroy() always executes DestroyImmediate

Both solutions work but I opted for the first since it has less side-effects, I don't know what's different in 2019 that makes this not work, but I think it has something to do with when Destroy actually destroys objects.

Esam-Bustaty commented 5 years ago

I also just tried a third solution which is to modify Utils.Destroy() like this:

internal static void Destroy<T>(ref T obj)
    where T : Object
{
    if (obj == null) return;

    if (Application.isPlaying)
        Object.Destroy(obj);
    else
        Object.DestroyImmediate(obj);

    obj = null;
}

and then adding the keyword ref to every call.

sasa42 commented 5 years ago

Hi, similiar behaviour in

Unity_2019_1_14f1 and Unity_2019_2_1f1 with Klak_Spout v0.2.4

on a simple sender and receiver scene. The Flicker from high frequence only happens in PlayMode.

sasa42 commented 5 years ago

Thanks for the fixes. Is there a recommendation for one of the 3 methods and could one ofthem be integrated in an new release?

keijiro commented 4 years ago

Thank you very much for suggesting the fix. I applied it in 7eb9fd5