-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[*] Concerns about safety, errors handling and inconsistencies #4751
Comments
One probably-unhelpful comment: When "user" is used above, the developer of a raylib-based application is meant. The problem is when that application is distributed to end-users and the application fails in a place where log messages, even if actually produced, are invisible and unknown to the casual user. It is for this situation that defensive programming is valuable. Also, raylib-internal operations may also need to be defensively programmed, as indicated in some places already, where a problem is not protectable above the API, it being related to under-the-covers failures. That could also apply to unchecked inputs from above that violate API pre-conditions. Perhaps the pre-conditions should be carefully explicit every and all the time. The worry should be about defective distributed executables. That's without considering the creation or corruption of an app for malicious purposes. |
(I'm the author of the reddit post) Apologies for not reporting this earlier. I wanted to gather some info/statistics about API before moving this to Github in order to be more specific. Sadly, I had no spare time to do this and thought maybe reddit/discord discussion was more appropriate. Thanks for forwarding the issue @raysan5 I may later report/patch some of those issues mentioned below (I need to test them more deeply). I'm still learning about raylib's API and reading how its code works under the hood. If someone wishes to grab some of these, feel free. Those are just my observations/concerns. I hope noone gets offended by them. If there is something wrong in this post, let me know and I'll try to reword it. (Also, writing this for the 2nd time as I closed browser by mistake while testing WASM32...)
Yes. Exacly. I'll try to use word "developer" from now on to avoid any confusion.
Well, I'm not really concerned with the raylib being used in malicious way, or that the end-users (not developers but users of application) will have hard time understanding what's going on. My main concern and point of view is that the library should allow the developer to decide where to crash, abort, or recover, and API should be consistent and explicit about it.
This is NOT a problem (at leas not to me) because most of underlying calls (deeper than the raylib API itself) set some kind of static error code, e.g. ISO/POSIX LibC sets
The problem with this one is that some raylib functions can fail in multiple cases. Validating all those cases would often just double the work that the underlying call can/will redo anyway. See the point 3 and 4 down below. My main concerns (partially mentioned in Reddit post):
|
Raylib allows for providing custom allocators via macros. GLFW supports this too, but via function pointers. Make sure that GLFW uses those Raylib macros, by wrapping them in function calls and setting them up inside of InitPlatform(). This is possible because of glfwInitAllocator() and GLFWallocator. Fixes: raysan5#4776 Relates-to: raysan5#4751
…#4777) Raylib allows for providing custom allocators via macros. GLFW supports this too, but via function pointers. Make sure that GLFW uses those Raylib macros, by wrapping them in function calls and setting them up inside of InitPlatform(). This is possible because of glfwInitAllocator() and GLFWallocator. Fixes: #4776 Relates-to: #4751
I figured I would add something to the discussion, however useless it may be. I'm developing a library roughly similar to Raylib. (not released or open yet), It uses more or less the opposite approach:
This does mean data is frequently copied where a simple pointer would work. But I've had enough trouble with libraries that expose their internal allocations and/or expect the user to expose theirs. My library separates errors into three categories:
Memory allocations are not checked. If you can't allocate memory, you're probably screwed anyway. User errors and Assert errors are asserts, in the sense that they trigger the debugger and exit the program. An external error causes the function it occurred in to return a bad return code, and also triggers an error callback with additional information. In fact, all asserts trigger an error callback, so the user can do any of their own debugger / assert logic. Finally, all error checking is entirely optional. The user doesn't have to look at the error return code. Neither do they have to set an error callback. All asserts and error checking can be enabled or disabled with some macro definitions, which are of course exposed in the build system with sensible defaults. This is just my approach - honestly I'm not sure how much of this is useful for Raylib. |
@bluesillybeard Thanks for sharing, definitely a different approach than raylib one. |
This issue is related to a reddit post about errors handling and inconsistencies.
raylib original approach was a hard focused on simplicity, trying to avoid any extra-code that could pollute the functions, leaving the security data checks to the users and expecting the data to be provided to most functions to be valid data.
But raylib has been +11 years in development and in that time some data validation checks have been added here and there resulting in some inconsistencies... and polluting the functions code with some things I originally tried to avoid (i.e early-returns).
Still, I tried to follow some principles in the library:
assert()
orexit()
.\0
terminated strings, it's up to the user to make sure that happens.This issue is open to analyze if there could be some of those tentative rules not applied in some functions or if there are some inconsistencies.
The text was updated successfully, but these errors were encountered: