Crash handling in GDExtension plugin
Asked Answered
K

5

0

How should I handle exceptions in my plugins? I tried using various libraries and in some cases they can break Godot, which leads to the program crashing.

Kronos answered 11/10, 2023 at 1:34 Comment(0)
S
0

Don't intentionally throw exceptions from your plugin unless there's no other recourse. If you are calling into a library function that is unsafe, it makes sense IMO to try/catch around that, but otherwise it's better to predict possible errors, do good type/null/etc checking, and print the error and return null/empty/ERROR_CODE/etc if there's an issue.

Schober answered 11/10, 2023 at 1:43 Comment(0)
K
0

Schober I tried using try/catch(...) but something happens inside the called function that breaks the program and does not exit in catch.

Kronos answered 11/10, 2023 at 9:25 Comment(0)
S
0

Kronos

What library & function is it?

Schober answered 11/10, 2023 at 17:36 Comment(0)
R
0

If you're on Windows, you can try using Windows OS function 'SetUnhandledExceptionFilter' to catch the error.

Reference: https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-setunhandledexceptionfilter

Example: https://www.codeproject.com/articles/154686/setunhandledexceptionfilter-and-the-c-c-runtime-li

Repertoire answered 11/10, 2023 at 22:47 Comment(0)
K
0

Schober It's Assimp and function is ReadFile from Importer

#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
...
const aiScene* scene = importer.ReadFile(path,
	aiProcess_GlobalScale |
	aiProcess_OptimizeMeshes |
	aiProcess_LimitBoneWeights |
	aiProcess_JoinIdenticalVertices |
	aiProcess_Triangulate);
Kronos answered 11/10, 2023 at 23:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.