Commit 14e3ceaa authored by Martin Finkel's avatar Martin Finkel
Browse files

clear stuff on Cleanup and add defensive code to C# script

with old build from 0.0.3 release + update c++ plugin and this Unity script, it doesn't crash or asserts (still leaks from libvlc)
parent 492b5749
......@@ -454,7 +454,34 @@ bool RenderAPI_D3D11::Setup( const libvlc_video_direct3d_device_cfg_t *cfg, libv
void RenderAPI_D3D11::Cleanup()
{
// here we can release all things Direct3D11 for good (if playing only one file)
if (m_textureRenderTarget)
{
m_textureRenderTarget->Release();
m_textureRenderTarget = NULL;
}
if(m_sharedHandle)
{
CloseHandle(m_sharedHandle);
m_sharedHandle = nullptr;
}
if(m_outputTexture)
{
m_outputTexture->Release();
m_outputTexture = nullptr;
}
if (m_textureUnity)
{
m_textureUnity->Release();
m_textureUnity = NULL;
}
if(m_textureShaderInput)
{
m_textureShaderInput->Release();
m_textureShaderInput = nullptr;
}
}
void RenderAPI_D3D11::Resize(void (*report_size_change)(void *report_opaque, unsigned width, unsigned height),
......
......@@ -10,6 +10,7 @@ public class UseRenderingPlugin : MonoBehaviour
const int seekTimeDelta = 2000;
Texture2D tex = null;
bool playing;
void Awake()
{
Core.Initialize(Application.dataPath);
......@@ -55,6 +56,7 @@ public void PlayPause()
}
else
{
playing = true;
if(_mediaPlayer.Media == null)
{
_mediaPlayer.Media = new Media(_libVLC, "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", FromType.FromLocation);
......@@ -68,8 +70,8 @@ public void Stop ()
{
Debug.Log ("[VLC] Stopping Player !");
playing = false;
_mediaPlayer?.Stop();
tex = null;
GetComponent<Renderer>().material.mainTexture = null;
}
......@@ -85,7 +87,7 @@ private IEnumerator CallPluginAtEndOfFrames()
yield return new WaitForEndOfFrame();
// We may not receive video size the first time
if (tex == null)
if (GetComponent<Renderer>().material.mainTexture == null && playing)
{
// If received size is not null, it and scale the texture
uint i_videoHeight = 0;
......@@ -102,12 +104,10 @@ private IEnumerator CallPluginAtEndOfFrames()
false,
true,
texptr);
tex.filterMode = FilterMode.Point;
tex.Apply();
GetComponent<Renderer>().material.mainTexture = tex;
}
}
else if (tex != null)
else if (tex != null && playing)
{
IntPtr texptr = _mediaPlayer.GetTexture(out bool updated);
if (updated)
......@@ -117,4 +117,4 @@ private IEnumerator CallPluginAtEndOfFrames()
}
}
}
}
\ No newline at end of file
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment