Skip to content
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

delete crash #97

Closed
fluxionary opened this issue Jun 4, 2023 · 7 comments
Closed

delete crash #97

fluxionary opened this issue Jun 4, 2023 · 7 comments
Labels
Bug Something isn't working
Milestone

Comments

@fluxionary
Copy link
Member

fluxionary commented Jun 4, 2023

using the most recent version (fab6f1a)

2023-06-04 19:03:45: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'mail' in callback on_playerReceiveFields(): .../mt/5.7.0/Minetest_test/bin/../mods/mail_mod/storage.lua:119: attempt to index a nil value
2023-06-04 19:03:45: ERROR[Main]: stack traceback:
2023-06-04 19:03:45: ERROR[Main]: 	.../mt/5.7.0/Minetest_test/bin/../mods/mail_mod/storage.lua:119: in function 'delete_mail'
2023-06-04 19:03:45: ERROR[Main]: 	...t/5.7.0/Minetest_test/bin/../mods/mail_mod/ui/events.lua:190: in function 'func'
2023-06-04 19:03:45: ERROR[Main]: 	...inetest_test/bin/../builtin/profiler/instrumentation.lua:108: in function <...inetest_test/bin/../builtin/profiler/instrumentation.lua:101>
2023-06-04 19:03:45: ERROR[Main]: 	.../mt/5.7.0/Minetest_test/bin/../builtin/game/register.lua:446: in function <.../mt/5.7.0/Minetest_test/bin/../builtin/game/register.lua:432>

the user reports:

  • What I was trying to do is to delete all mails. "Select all" confuses me (do selected mails have darker or lighter color?), so I just selected them all with shift+arrows, then pressed "delete" and nothing happened. After that I pressed "Select all" again and pressed "delete" again and it crashed.
@BuckarooBanzay BuckarooBanzay added the Bug Something isn't working label Jun 5, 2023
@BuckarooBanzay
Copy link
Member

BuckarooBanzay commented Jun 5, 2023

Hm, this looks like the player doesn't have mails in the inbox to iterate through:

if entry.inbox[i].id == deleted_msg then

😕
(or maybe they are deleted already...)

EDIT: you might have to add a break here:

	for i = #entry.inbox, 1, -1 do
		for _, deleted_msg in ipairs(msg_ids) do
			if entry.inbox[i].id == deleted_msg then
				table.remove(entry.inbox, i)
				break -- <<<<
			end
		end
	end

otherwise it might remove multiple messages in a single pass of the outer loop (#entry.inbox, 1, -1) and the i index points to outside of the inbox-list

See #98 for a partial fix

BuckarooBanzay added a commit that referenced this issue Jun 5, 2023
Athozus added a commit that referenced this issue Jun 5, 2023
@Athozus
Copy link
Member

Athozus commented Jun 5, 2023

@BuckarooBanzay you're removing the multiple deletion system by adding a break. I just added a verification of entry lengths, and it is fixed.

@Athozus Athozus closed this as completed Jun 5, 2023
Athozus added a commit that referenced this issue Jun 5, 2023
* partial fox for #97

* Fix #97

---------

Co-authored-by: BuckarooBanzay <[email protected]>
Co-authored-by: Athozus <[email protected]>
@BuckarooBanzay
Copy link
Member

you're removing the multiple deletion system by adding a break

yeah, a break from the inner loop, the outer still loops and removes all selected messages...

@S-S-X
Copy link
Member

S-S-X commented Jun 5, 2023

For me it seems like this again should have been pull request instead direct commits. Just noticed it is, I just didn't see it for some reason...

Anyway, what @Athozus added does not actually do anything. For loop mechanisms already work as same expressions: Loop is never executed if table is empty.

On the other hand @BuckarooBanzay's commit does actually fix issue which basically is preventing from continuing operation on thing that is already removed in inner loop entry.outbox[i].

@S-S-X S-S-X reopened this Jun 5, 2023
@Athozus
Copy link
Member

Athozus commented Jun 5, 2023

yeah, a break from the inner loop, the outer still loops and removes all selected messages...

Sorry, my bad, I was too fast.

@S-S-X I do not think it does anything, when you have a 0 length it does a weird thing.

@S-S-X
Copy link
Member

S-S-X commented Jun 5, 2023

@S-S-X I do not think it does anything, when you have a 0 length it does a weird thing.

Just try it yourself, it is basic Lua and nothing else. Loop block is either executed or not and if table is empty it is not executed, if #t > 0 then is completely unnecessary because for i=#t,1,-1 do already does exactly same.

If you do not believe your eyes then just try it. Reason for crash is in inner loop which attempts to index past outer loop table after first removal.

(best thing to do would be to implement filter-by-shift method discussed on Discord but above stands if going to patch current methods)

@BuckarooBanzay
Copy link
Member

should be fixed with #99 otherwise reopen please

Athozus added a commit that referenced this issue Jun 20, 2023
* partial fox for #97

* Fix #97

---------

Co-authored-by: BuckarooBanzay <[email protected]>
Co-authored-by: Athozus <[email protected]>
@Athozus Athozus added this to the 1.2.0 milestone Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants