[0.18.34] Stack Overflow RtlCaptureContext

Bugs that are actually features.
Post Reply
User avatar
Cooldude2606
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Sat Sep 16, 2017 9:04 pm
Contact:

[0.18.34] Stack Overflow RtlCaptureContext

Post by Cooldude2606 »

While making a custom command to run code in a custom environment I found some strange cases that will result in the game crashing from a stack overflow centered around the following loop: (full log is attached)
Looping section of stacktrace
I found that certain combinations of gsub, game.print, pcall, xpcall, and function calls can result in a crash from stack overflow. However, some combinations do not cause any crashes.
When there is a crash it will be because there was an error in the loaded string, which is normally caught by pcall or xpcall.
When the loaded string has no errors then everything works as expected, for all cases.

Below you can find the minimum required code in order to reproduce the crash and all the cases that I found.
I dont know if the custom environment or the load function is the cause of the error which is why I have left both in my example.
The final case with pcall, raw_command_error and gsub will always work and shows the correct result for each test.
Minimum Scenario Code
Tests and Results
Attachments
factorio-current.log
(96.79 KiB) Downloaded 57 times
--- Developer for Explosive Gaming factorio community. Find our code on GitHub. Please contact me via our Discord. ---

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.18.34] Stack Overflow RtlCaptureContext

Post by Rseding91 »

Without actually running the code, it sounds like your error handling is throwing an error and repeatedly calls into the error handler causing a stack overflow.

Overall, I don't consider what ever you're trying to do resulting in an error something we want to try to address. I've said in the past and I say it again now: I don't think mods should ever need to use pcall and I think it's an error in most cases where a mod does use it. If I got to choose from the start then mods would not have access to using it.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Cooldude2606
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Sat Sep 16, 2017 9:04 pm
Contact:

Re: [0.18.34] Stack Overflow RtlCaptureContext

Post by Cooldude2606 »

Following your first message I decided to look into how xpcall works. And you were correct, the error handler caused an error which was then feed back into its self. I was not aware that xpcall would capture errors from the error handler and feed it back into the error handler, resulting in a stack overflow.

You can move this to not a bug rather than wont fix, since it was an error on my part.
--- Developer for Explosive Gaming factorio community. Find our code on GitHub. Please contact me via our Discord. ---

Post Reply

Return to “Not a bug”