Cannot use 'throw' with exceptions disabled (SOLVED)

Hi All,

I’m trying to run this facesnap project, but I get this error:

/facerec/include/dlib/image_processing/frontal_face_detector.h
    	Line 7: In file included from upload/facerec/src/facerec.cpp:16:    
    ...
    In file included from upload/facerec/include/extdlib/image_processing/../unicode.h:6:
        cannot use 'throw' with exceptions disabled
                    throw invalid_utf8_error();
                    ^
...

I know there is a similar issue here but unfortunately, none of that solutions are acceptable.

If I set the -fexceptions flag in /facerec/ext.manifest, I got that this flag is invalid.
Because this project uses a third-party lib (dlib), it’s not a good way to fix all of throw parts of the code.

So, how can I fix this error?
Or more generally, how to use properly native extension what depends on a third-party C++ library which contains exception handling? (I hope my question has to make sense. :grinning: )

Thanks in advance for the help!

You question makes good sense.

First, here’s our section from the manual on exceptions:

"

No C++ Exceptions

We don’t make use of any exceptions in the engine.
It isn’t generally used in game engines, since the data is (mostly) known beforehand, during development.
Removing the support for C++ exceptions decreases executable size and improves the runtime performance.
"

We work hard on keeping the runtime as small and as fast as possible, and having good defaults is part of “keeping a clean house” so you don’t get surprises further down the road when you want to ship your game.

Now, we made that example a long time ago, and since then we’ve made changes that apparently make this not build properly. This was obviously not our intention.

Currently we don’t have a way of removing flags from the command line, but we’ll see how we can make that extension work again.

As for other 3rdparty libs using exceptions, you’d just have to wait a bit until we can support it again.

That said, I’d really recommend searching for 3rd party libraries not using exceptions, STL, boost, too much templates etc, as these can bloat the code, slow down the code, and also take longer to build.
(You can read more here and here).

In our case, we just needed a cool demo, and dlib was the one that we found at the time. It uses exceptions, and also requires a big data file (100mb?) to go with it so it’s not that practical to use on a mobile. But, it was useful as an example, and we should definitely make it work again, perhaps by replacing dlib altogether.

4 Likes

Thank you @Mathias_Westerdahl!
I totally understand your viewpoint/concept and agree with you. You guys do great work with Defold. I think it’s a very great product, like it so much.

The reason why I choose the mentioned facesnap, because I would like to use face detection in my app. dlib seems a good choice to me for this.
As I see, does not exist a proper way to use it yet. :slightly_smiling_face:
Could you please recommend a library what I can use it to the same goal?

1 Like

As I see, does not exist a proper way to use it yet

Yes, sorry again for breaking this. We should fix it soon.

Could you please recommend a library what I can use it to the same goal?

At the time, I also looked into OpenCV, but I think it was just easiest to “get started” with.
There are probably more libraries available now. I just searched through Github at the time, looking for something to test with. But as I mentioned, the libraries like dlib (machine trained) use a data file, and that might be too large for actual mobile/html5 games.

1 Like

OK. Thank you for your help!
I’m still investigating it a bit. :wink:

1 Like