Download

Build Crash on opening when using third party library (Dlib)

Hello,

I was able to add OpenCV and Dlib into Unreal engine 4.25 and everything is working as expected.
The build of the project is completed successfully but when I open the project i get this wired error:
Assertion failed: png_ptr
[File:D:/Build/++UE+Licensee/Sync/Engine/Source/Runtime/ImageWrapper/Private/Formats/PngImageWrapper.cpp] [Line: 427]

When I build with only OpenCV everything is ok but when I add the Dlib I get the above error.
I have to say that this is an empty ThirdPerson Template and I didn`t import any png files and there are non in the lib…

What could cause this issue? how could I investigate it better? there is also no information in the log files…

Thanks,
Doron

UE4 has png.h the version of which is 1.5.2, on the other hand, Dlib also has png.h 1.6.7.
I don’t know the detail but maybe those make a conflict when PngImageWrapper.cpp calls PNG_LIBPNG_VER_STRING macro in line 426. (I use 4.22, so that the line is 424 in my case.)
Then it calls check macro with null_ptr because png_ptr is failed to be initialized.

I think the problem is so, but I don’t know how to solve. I tried to rewrite the code in PngImageWrapper.cpp, but assertion failure remains.
I’m not good at C++. Can anyone help us?

As an aside, if you want to use OpenCV on UE4, maybe you shouldn’t use 4.25. I don’t know why but when you include some headers, you’ll face some stinky macro conflicts.
But if you’ve done it, please tell me how. In fact, I also want to use 4.25, but I faced some problems on 4.25 so I use 4.22.

In addition, you’ll face a problem related to “UpdateResource()” in the UTextureCube.h and UCanvasRenderTarget2D.h.
If so, you have to change the code in those source. Just add “#undef UpdateResource” before the definition of “virtual void UpdateResource() override;”
This is because Dlib has dependency on winbase.h, and it has UpdateResource macro which calls UpdateResourceW().
It is scary to change the engine source, but those changes are needed and there should be no problems when just adding #undef code.

And, in YourProject.build.cs, add “bEnableExceptions = true;” and “bEnableUndefinedIdentifierWarnings = false;”.
When packaging, try catch doesn’t work if bEnableExceptions is set to false.
When building your solution, it makes tons of errors if bEnableUndefinedIdentifierWarnings is set to true.

Thank you @creatorue I just saw this message now :o
At the end I was able to make it work, basically what I did was to compile the Dlib lib without png support and made some modification in the header files.
If you want I can share with you the lib and headers.

Also faced the UpdateResource and other issues but solved them as you also suggested.

Thanks for your comment!

best regards,
Doron

Please share this! I was able to get an older version of a OpenCV, and OpenFace working (Found on github) but its a mess!