# Cinder-WMFVideo with C++17 and VS2019

**URL:** https://discourse.libcinder.org/t/cinder-wmfvideo-with-c-17-and-vs2019/1814
**Category:** CinderBlocks
**Created:** [April 28, 2021, 12:12am UTC](https://discourse.libcinder.org/t/cinder-wmfvideo-with-c-17-and-vs2019/1814 "2021-04-28T00:12:51Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![morphogencc](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@morphogencc](https://discourse.libcinder.org/u/morphogencc)
#### Post date: [April 28, 2021, 12:12am UTC](https://discourse.libcinder.org/t/cinder-wmfvideo-with-c-17-and-vs2019/1814/1 "2021-04-28T00:12:51Z")

</div>

I’ve been trying to get the WMFVideo block to work with C++17 and VS2019 as a x64 build, but with little luck so far…

Based off of a [previous thread](https://discourse.libcinder.org/t/options-for-windows-based-hardware-accelerated-video-in-cinder-0-9-2-dev/1608/10), I went into [linkedlist.h](https://github.com/sitara-systems/Cinder-WMFVideo/blob/master/src/presenter/common/linklist.h) and changed:

`const Node *pNode`  
to  
`typename const List<T*>::Node *pNode`

as well as changing the headers from `glload/wgl_all.h` to `glad/glad_wgl.h` for the interops. This allows the code to compile and the VideoTexture sample runs, but the VideoPlayback sample crashes with an exception every time I run it.

The exception seems to be related to calls to `->AddRef()`, which is a part of the Win32 COM API:

```cpp

      HRESULT GetItem(typename const List<T*>::Node *pNode, Ptr* ppItem)
        {
            Ptr pItem = NULL;

            // The base class gives us the pointer without AddRef'ing it.
            // If we return the pointer to the caller, we must AddRef().
            HRESULT hr = List<Ptr>::GetItem(pNode, &pItem);
            if (SUCCEEDED(hr))
            {
                assert(pItem || NULLABLE);
                if (pItem)
                {
                    *ppItem = pItem;
                    (*ppItem)->AddRef();
                }
            }
            return hr;
        }

```

Visual Studio gives me an error output:

```auto
'SimplePlayBack.exe' (Win32): Loaded 'C:\Windows\System32\mfmp4srcsnk.dll'. 
Exception thrown at 0x00007FFD83C94B59 in SimplePlayBack.exe: Microsoft C++ exception: bad_hresult at memory location 0x000000000014DD50.
Exception thrown at 0x00007FFD83C94B59 in SimplePlayBack.exe: Microsoft C++ exception: bad_hresult at memory location 0x000000000014DD28.
Exception thrown at 0x00007FFD83C94B59 in SimplePlayBack.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
Exception thrown at 0x00007FFD83C94B59 in SimplePlayBack.exe: Microsoft C++ exception: bad_hresult at memory location 0x000000000014DD28.

```

After a few times stepping through the code, the issue is at `AddRef()` in `GetItem()`.

This is getting a little bit further into the weeds of how Windows works than I’m comfortable with, so I’ve gotten stuck and thought I’d throw up a bat signal for some assistance… does anyone know exactly how this Windows API works, and why this call would be causing exceptions in the player?

My latest working version of [Cinder-WMFVideo](https://github.com/sitara-systems/Cinder-WMFVideo) is available on github.

---

<div class="post-metadata">

### Author: ![Gazoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gazoo/32/61_2.png) [@Gazoo](https://discourse.libcinder.org/u/Gazoo)
#### Post date: [April 28, 2021, 5:52am UTC](https://discourse.libcinder.org/t/cinder-wmfvideo-with-c-17-and-vs2019/1814/2 "2021-04-28T05:52:56Z")

</div>

This may be a silly question, but does ignoring the exception still allow for the playback to occur? I find that Cinder-WMFVideo will also often Exceptions in my own codebase, but ignoring them doesn’t seem to impact execution.

For the record, I’m sure it’s not healthy to just outright ignore them, but they’re thrown in areas that I have little understanding of, and not found the time to further investigate.

Cheers,  
Gazoo

---

<div class="post-metadata">

### Author: ![morphogencc](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@morphogencc](https://discourse.libcinder.org/u/morphogencc)
#### Post date: [April 28, 2021, 5:23pm UTC](https://discourse.libcinder.org/t/cinder-wmfvideo-with-c-17-and-vs2019/1814/3 "2021-04-28T17:23:55Z")

</div>

If I ignore these exceptions, I’ll eventually get a read access violation exception… so it seems like I need to figure out what’s going on here, unfortunately ☹

---

<div class="post-metadata">

### Author: ![Gazoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gazoo/32/61_2.png) [@Gazoo](https://discourse.libcinder.org/u/Gazoo)
#### Post date: [May 9, 2021, 1:09am UTC](https://discourse.libcinder.org/t/cinder-wmfvideo-with-c-17-and-vs2019/1814/4 "2021-05-09T01:09:52Z")

</div>

It might be worthwhile giving other forks of the WMFVideo code a shot. @paul.houx has done a fair amount of work iirc, and his branch would be the first I’d give a shot just to see if anything changes.

I also recall @paul.houx taking a break from having anything to do with the apparent nightmare that is working with accelerated video decoding in Windows if the goal is to eventually get the output to an OpenGL texture. So if nothing seems to budge with WMFVideo there are other possible options to explore:

> [@Options for windows-based hardware accelerated video in Cinder 0.9.2-dev](https://discourse.libcinder.org/t/options-for-windows-based-hardware-accelerated-video-in-cinder-0-9-2-dev/1608):
>
> Hey Embers, I know this topic rolls around every few years, but since I hadn’t seen one in recent times I thought I’d stick my head out and ask what, if any, experience other developers have with hardware accelerated video playback in Windows, in Cinder? About two years ago I used the often cited WMFVideo block. However, with my current codebase this block just seems to throw a fit, specifically it seems to cause an access read violation when I snag enough memory. hr = OnSessionEvent( pEvent,…

aaaaaand I just noticed you’ve commented on that thread, so you’re well aware of it 🙂

---

<div class="post-metadata">

### Author: ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)
#### Post date: [May 10, 2021, 6:23am UTC](https://discourse.libcinder.org/t/cinder-wmfvideo-with-c-17-and-vs2019/1814/5 "2021-05-10T06:23:42Z")

</div>

Any progress on this mate? I’ve just run into the same issue and hoping you can spare me a bughunting session.

---

<div class="post-metadata">

### Author: ![morphogencc](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@morphogencc](https://discourse.libcinder.org/u/morphogencc)
#### Post date: [May 10, 2021, 8:39pm UTC](https://discourse.libcinder.org/t/cinder-wmfvideo-with-c-17-and-vs2019/1814/6 "2021-05-10T20:39:40Z")

</div>

Unfortunately not…

The error seems to happen in `EVRCustomPresenter::SetMediaType` when the handler is fetching the Video Samples; I haven’t dug deeper down the rabbithole yet. I bailed and tried to get VLC or FFMPEG working as a video player, but both of those have also resulted in deep rabbitholes…

Many of the helper functions are lifted directly from the Windows Media Foundation examples from 2016, so it seems most likely to me that something changed in the Windows API or COM Interface, though that’s really just a hunch.

I may take a deeper look this week at it; if you find another video player that’s working out-of-the-box with the latest VS2019/C++17, I’d love to take a look…

---

<div class="post-metadata">

### Author: ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)
#### Post date: [May 12, 2021, 2:20am UTC](https://discourse.libcinder.org/t/cinder-wmfvideo-with-c-17-and-vs2019/1814/7 "2021-05-12T02:20:13Z")

</div>

Ok mate, I think I’ve figured it out. I had decided to revert to an older version of cinder and visual studio that didn’t have these issues for the project I’m just starting and everything was chugging along fine until I accidentally updated the ciWMFVideoPlayer and suddenly I started seeing the access violation again in the same location.

I had a quick look at at what was different between the two versions and all I could see were the aforementioned changes to `linklist.h` that updated some of the `typedefs` used. Not sure how I didn’t see it originally but it was one of those classic C++ vtable-y footguns where the `Node` typedef was not correctly specified to use the correct `T`, which would explain why the error was in such a strange place. Honestly I’d have expected the compiler to catch it but it didn’t so here we are.

Long story short, there’s a working fork on my github [here](https://github.com/axjxwright/Cinder-WMFVideo). I submitted an issue to the Potion guys erroneously yesterday so I’ll go and clear that up with them, and if they want to merge my changes into their `vs2019` branch that’s up to them.

Cheers,

A

---

<div class="post-metadata">

### Author: ![morphogencc](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@morphogencc](https://discourse.libcinder.org/u/morphogencc)
#### Post date: [May 13, 2021, 7:11pm UTC](https://discourse.libcinder.org/t/cinder-wmfvideo-with-c-17-and-vs2019/1814/8 "2021-05-13T19:11:08Z")

</div>

Brilliant!

I just pulled it and it’s working great for me as well. Surprised that the compiler didn’t catch it, but totally jazzed that we have working video again!

thanks so much!
