Make ScmFunction lookup 1-based#550
Conversation
MiranDMC
left a comment
There was a problem hiding this comment.
There is zero error checks for scenarios outside normal working conditions.
|
Storage validates max capacity, it is the only thing it should care. Anything else is validated on the caller side. Get should not throw errors, because it can be used, e.g. for counting of used/free spots. |
Then implement checks in other places. I'm bored of wasting time troubleshooting crashes that could be prevented by basic coding discipline. |
|
Does this MR fix the issue with the script in the first post? What other crashes you think of? |
It should be method of the class then. Nobody has businesses to do things like that from outside. |
Any situation where invalid input arguments are used. Referencing not allocated/already deleted function ID is sign of serious problems. Currently situations like that are silently ignored, or some other function is returned if it happens to exists at that slot. |
I'm not fixing imaginary issues. I spent last 6 months tirelessly fixing concrete, difficult bugs, caused sometimes by careless refactoring. If you have a specific scenario, please share it. Talk is cheap. |
| { | ||
| ScmFunction* ScmFunction::store[Store_Size] = {0}; | ||
| size_t ScmFunction::allocationPlace = 0; | ||
| const size_t Default_Index = 1; |
There was a problem hiding this comment.
Two year of refactoring and you adding stuff like this. Why not declared in header file. Why it is member of CLEO namespace?
There was a problem hiding this comment.
Because it is class related property. Single look at header gives idea about general contents of the entire class.
There was a problem hiding this comment.
constants belong to the logic in my book. why would I need to open header when I have my cpp file open? It's only used here
There was a problem hiding this comment.
That's how spaghetti is created. You either look at the header and have general idea what it is all about or spend time analyzing every function inside cpp file.
|
Technically fixes the issue but entire solution is so lazy it is even below vibe-coding quality. I would give approval but I'm not looking forward for rebaseing my branch. |
lol. Ok, show me how your BULLETPROOF coding solution helps to catch errors in this case |
On master branch your example only allocates function with index 0 then tries to use index 1. Updated the script: Key breaking infinite loop was added. As previously "after foo" is executed by script B, but then after pressing 1 button error is shown: Meanwhile on the version from #537 error is thrown the moment B script calls return: After disabling script logging error is thrown also the moment script B tries to return: |
Updated B script |
|
|
I used version from #537 and it does not produce any errors in the code I posted. But it shows "after foo". |
Right, it does after running second game session. Bug introduced during implementation of idea of skipping slot 0. I have to untangle it. |
By doing |
maybe, I did not validate that, the idea was to modify other two bytes |
|
It is not gonna to be bullet proof. But corrupted function id will not always target already allocated slots. Then the correct error message makes sense. Per script storage would make it more likely to hit empty slots and would solve problem of cross execution. But there come external scripts that we do not know when they get terminated. Another problem I spotted is after script termination its call stack is not cleared in the storage. |
Is that true on this branch? My understanding is that it should eventually hit id=0 and stop. |
Case I had shows it is somehow possible. Take note the script can get corrupted id then go forward and call more functions. |
there is only one public function that allows it: CLEO_GetCleoCallStackSize. And It should handle this case better then, instead of default to 0. It can return -1 to the caller and let them decide how to handle this. The logger can put error message in the log, other library can ignore it, third library can show error message, etc. |
|
Should it really be caller role to decide if and how to report corruption inside the CLEO? CLEO_GetCleoCallStackSize takes as argument the script pointer, not function id. So there is no other scenario than severe problem already happened or is about to happen. |
|
There is another issue. Now I'm getting heap corruption error when:
Happens on master, this branch, and the #537 too. Call stack leads to: It also occurred before I rebased to current master (without recent custom mission BaseIP changes). |
|
Double free |
|
Well, BaseIP is also stored in ScmFunction stack entry. It is needed when switching modules. I added fixes to the other branch, but it still does not solve this case. If script uses other thread's return it restores its BaseIP as its own. |
|
Ok seems I squished all issues on the other branch. "after foo" no longer is executed by B, A is unaffected at all, double free and few other bugs found and fixed. |
|
|
Moving forward with MVP for better stability |




Without fix:
With fix:
Nothing is printed