[C++] Event Bugfix

11/15/2014 23:51 Lefloyd#1
Hey,

German:

English (not perfect :D):

#UPDATE#:
I've written an example code to demonstrate you the bug in an easier way (at least for ppl who can program a bit).
Example result of the output WITHOUT my fix: [Only registered and activated users can see links. Click Here To Register...]
Example result of the output WITH my fix: [Only registered and activated users can see links. Click Here To Register...]
I added the 2 example files in the appendix - you just has to include the file "ExampleEventbug.h" in your cmd.cpp, write a function like this:
Code:
ACMD (do_call_example_script)
{
	CallExampleScript(ch);
}
And add the function into the command-list; just add the following code in the "cmd_info"-array:
Code:
{ "call_example_script",	do_call_example_script,	0,	POS_DEAD,	GM_IMPLEMENTOR },
Now you can go ingame (after compiling) and check out the output when you enter "/call_example_script" with and without my fix - you'll see same results as i've shown you in the screens. So without the 2. event won't be executed and with it will be.
#END OF UPDATE#

Vielleicht hilft es ja dem Einen oder Anderem ;)

Kind Regards
11/15/2014 23:59 .Raicon#2
Wie gewohnt, schlicht und einfach erklärt.

Danke für das Release.


LG .Raicon
11/16/2014 01:44 .BasH^##3
Danke ich war schon am verzweifeln :D :D
11/16/2014 05:55 LovecKrys#4
And now in english.
11/16/2014 06:29 Lefloyd#5
Added in english. If someone wanna write a better english translation - he may. :D
11/17/2014 12:06 Lefloyd#6
#UPDATE#
I've got a request to give you an example for the bug - maybe I was a bit inaccurate in describing it. Well, I've added an example-file that you can compile and see how the fix works.

Kind Regards
11/17/2014 15:19 lollo_9_1#7
Quote:
Originally Posted by Lefloyd View Post
#UPDATE#
I've got a request to give you an example for the bug - maybe I was a bit inaccurate in describing it. Well, I've added an example-file that you can compile and see how the fix works.

Kind Regards
I tried the code inside the ExampleEventbug.cpp file, but it worked fine without using your fix: (I just pasted it inside cmd.cpp)
[Only registered and activated users can see links. Click Here To Register...]
It's a test server so, that character is the only one logged in. (I tried to spawn mobs/kill them/kill regen-spawned mobs/pull all/respawn all, but it didn't get bugs)

If we consider your two screenshots (1. [Only registered and activated users can see links. Click Here To Register...] 2. [Only registered and activated users can see links. Click Here To Register...]) we can easily figure out that event1 and event2 are pointing to the same queueElementPtr. So, when you call event_cancel(&f_pkEvent1); you are instead calling event_cancel(&f_pkEvent2);, due to an incrementing issue that moves f_pkEvent1 to f_pkEvent1"-1" and f_pkEvent2 (f_pkEvent1"+1" in theory) to f_pkEvent1. (f_pkEvent1->q_el-1 to be more precise) (is this what you wrote above in the first post?)
Why? When you call f_pkEvent2 = event_create(example_event2, info, PASSES_PER_SEC(3)); you're adding a new event in the event list using the [Only registered and activated users can see links. Click Here To Register...] function, which adds the event at the end of the list if it doesn't find a clone (or a greater one, but I don't think this is the case), which means you already have this event in your event list and you, but only you, got this bug due to a weird implementation you made.
If other people got this bug using not-so-modded-source-files, maybe the trigger of such issue is to refer to something else. I haven't got it yet.
I don't think a trivial the_event->q_el = NULL; could make the difference in there. (it's just a pointer, otherwise we would have thought about an overloaded assignment operator fault)

Speaking of which, is dominion_manager.cpp part of the files to test or did you put it in the .rar instead of ExampleEventbug.h?
11/17/2014 15:34 Lefloyd#8
Thanks for your reply lollo_9_1, that what you explained was that what I tried to explain. I also thought when I found out the source of the bug that the bug would not be there ANY time because some times the address will be refered by some other things before the new create_event is called, but in my files it occurs when I don't add my fix. And yes, this NULL set will fix the bug (when it would occur) because the event_cancel set's the "bCancel" variable in the queueElement that is refered through "q_el" from the eventPtr. If the eventPtr has the reference of the queueElement of another event (the new event) it will cancel it - if there is a NULL pointer it will do nothing. That's why this fix works. And yes, it won't occur everytime but it CAN occur - I know this for sure because it does occur at my files if I haven't changed the position of the NULL pointer setting..

I hope you understand what I'm trying to say, I knew why the error came (I explained it in my first post) I just send the pictures to show you what the results can be like.

€dit: And no, the dominion_manager wasn't a part of the example, sorry for uploading it.^^ I've already deleted it in the rar-file.
€dit2: And why it doesn't work at you (the error) is because your queueElementPtr hadn't be the same - maybe it's also different from system to system if the bug occurs. But there can be the case, that it occurs.^^
€dit3: Aaand without my fix I'd wonder if he wouldn't set the bCancel of a address which is already destroyed... and I can't believe that this is good :o

Kind Regards
11/17/2014 19:05 .iRyan#9
Thanks for this release!