Do you require further details to be included or just a simple "filename" param?
I was thinking about maybe showing the contents of the objects too, but I don't want to make too much work for you
Quote:
Originally Posted by Neuro Toxin
A Collection inherits an ArrayList. This means you're expected to manage the pointer like any other standard sourcepawn handle.
Eg. delete / == null
So I should be using delete to remove a collection as I'm guessing the collection is just a list of pointers to existing objects, so closing the collection on its own won't recursively delete the objects inside it, Is there a method which achieves this?
Quote:
Originally Posted by Neuro Toxin
KeyValues operations are currently only supported on real Dynamic objects.
So I should be using delete to remove a collection as I'm guessing the collection is just a list of pointers to existing objects, so closing the collection on its own won't recursively delete the objects inside it, Is there a method which achieves this?.
#if defined _dynamic_class_testdyn_
#endinput
#endif
#define _dynamic_class_testdyn_
methodmap TestDyn < Dynamic
{
public TestDyn()
{
// First we make a new dymanic object
Dynamic myclass = Dynamic(64, 0);
// Next we will define all the members
// -> We do this to force the offsets to always be in the same location
// over multiple instances of the same class.
myclass.SetFloat("time", 0.0000000);
return view_as<TestDyn>(myclass);
}
// Note that I use static offsets to access members.
// -> This improves performance by caching member offsets
// -> This is why we force the members in during the contructor
// -> Failure to force members in the constructor will cause corruption
property float time
{
public get()
{
static DynamicOffset offset = INVALID_DYNAMIC_OFFSET;
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.GetMemberOffset("time");
if (offset == INVALID_DYNAMIC_OFFSET)
SetFailState("A serious error occured in Dynamic!");
}
return this.GetFloatByOffset(offset);
}
public set(float value)
{
static DynamicOffset offset = INVALID_DYNAMIC_OFFSET;
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.GetMemberOffset("time");
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.SetFloat("time", value);
return;
}
}
this.SetFloatByOffset(offset, value);
}
}
}
and this results in the error. It only happens when i use a methodmap, if i use Dynamic by it self it works fine. I tried this on 2 different servers as well
Code:
L 03/03/2017 - 21:34:28: [SM] Exception reported: Invalid index 65 (count: 1)
L 03/03/2017 - 21:34:28: [SM] Blaming: dynamic.smx
L 03/03/2017 - 21:34:28: [SM] Call stack trace:
L 03/03/2017 - 21:34:28: [SM] [0] ArrayList.Get
L 03/03/2017 - 21:34:28: [SM] [1] Line 486, ..\dynamic.sp::_Dynamic_GetMemberDataType
L 03/03/2017 - 21:34:28: [SM] [2] Line 48, ..\dynamic/system/datatypes/float.sp::_SetFloat
L 03/03/2017 - 21:34:28: [SM] [3] Line 118, ..\dynamic/system/datatypes/float.sp::_Dynamic_SetFloatByOffset
L 03/03/2017 - 21:34:28: [SM] [4] Line 311, ..\dynamic/system/natives.sp::Native_Dynamic_SetFloatByOffset
L 03/03/2017 - 21:34:28: [SM] [6] Dynamic_SetFloatByOffset
L 03/03/2017 - 21:34:28: [SM] [7] Line 210, C:\Users\Josh\Documents\spedit1.2.0.1\sourcepawn\configs\sm_1_8_5914\include\dynamic/methodmaps/dynamic.inc::Dynamic.SetFloatByOffset
L 03/03/2017 - 21:34:28: [SM] [8] Line 50, C:\Users\Josh\Documents\timersurf\addons\sourcemod\scripting\include\testdyn.inc::TestDyn.time.set
L 03/03/2017 - 21:34:28: [SM] [9] Line 28, C:\Users\Josh\Desktop\testdyn.sp::OnPluginStart
Ohgodwhy didn't I find dynamic earlier?! Nice one! You should promote this more; maybe editing the Wiki accordingly?
Since I didn't used it in the wild: what is your feeling using this in high-performance-critical plugins such as looping through all players in OnGameFrame and doing some extensive lookup & storage operations? Do you have experience with that?
I understand that. If i make a regular dynamic and call the garbage collection command it will clean it up, however if I use a methodmap dynamic class it wont. Is that intended?
Still floats are still broken. I can use any other type but as soon as i use floats it breaks dynamic. Can you reproduce that issue while using a methodmap dynamic class?
edit:
I changed _SetFloat and _SetInt to print out the position its trying to access like so
Code:
stock Dynamic_MemberType _SetFloat(ArrayList data, int position, int offset, int blocksize, float value)
{
PrintToServer("Position: %i, offset %i", position, offset);
When trying to modify an int its position 0 and offset 0
When trying to modify a float its position 65 and offset 0.
Is that supposed to happen? The array length is 1 and its trying to access index 65.
edit2:
so i see you reserve up to MAXPLAYERS for client stuff which is 64, so it trying to access the 65th index makes sense. The only weird thing is when you do it with an int it will use position 0 (should be client reserved), however when you use a float it uses 65 (which should have just been created) and that index is invalid.
I modified
public void Initialise(Handle plugin, int blocksize=64, int startsize=0, bool persistent=false)
to display the index it is with "PrintToServer("From Initialise: index: %i ", me);"
this results in
Spoiler
From Initialise: index: 0
From Initialise: index: 1
From Initialise: index: 2
From Initialise: index: 3
From Initialise: index: 4
From Initialise: index: 5
From Initialise: index: 6
From Initialise: index: 7
From Initialise: index: 8
From Initialise: index: 9
From Initialise: index: 10
From Initialise: index: 11
From Initialise: index: 12
From Initialise: index: 13
From Initialise: index: 14
From Initialise: index: 15
From Initialise: index: 16
From Initialise: index: 17
From Initialise: index: 18
From Initialise: index: 19
From Initialise: index: 20
From Initialise: index: 21
From Initialise: index: 22
From Initialise: index: 23
From Initialise: index: 24
From Initialise: index: 25
From Initialise: index: 26
From Initialise: index: 27
From Initialise: index: 28
From Initialise: index: 29
From Initialise: index: 30
From Initialise: index: 31
From Initialise: index: 32
From Initialise: index: 33
From Initialise: index: 34
From Initialise: index: 35
From Initialise: index: 36
From Initialise: index: 37
From Initialise: index: 38
From Initialise: index: 39
From Initialise: index: 40
From Initialise: index: 41
From Initialise: index: 42
From Initialise: index: 43
From Initialise: index: 44
From Initialise: index: 45
From Initialise: index: 46
From Initialise: index: 47
From Initialise: index: 48
From Initialise: index: 49
From Initialise: index: 50
From Initialise: index: 51
From Initialise: index: 52
From Initialise: index: 53
From Initialise: index: 54
From Initialise: index: 55
From Initialise: index: 56
From Initialise: index: 57
From Initialise: index: 58
From Initialise: index: 59
From Initialise: index: 60
From Initialise: index: 61
From Initialise: index: 62
From Initialise: index: 63
From Initialise: index: 64
when loaded it prints out "From Initialise: index: 65"
okay cool, thats right. It should be MAXPLAYERS + 1 now.
When the rest of the code runs with my debug messages i get
Spoiler
//this stuff is happening from this, for some reason its using position 0.
public MyClass()
{
// First we make a new dymanic object
Dynamic myclass = Dynamic(64, 0);
// Next we will define all the members
// -> We do this to force the offsets to always be in the same location
// over multiple instances of the same class.
myclass.SetInt("int1", 2);
myclass.SetInt("int2", 0);
myclass.SetFloat("float1", 0.0);
myclass.SetBool("bool1", false);
return view_as<MyClass>(myclass);
}
//
Int Position: 0, offset 0
Int Position: 0, offset 2
Float Position: 0, offset 4 <----- Why is it position 0 here
Bool Position: 0, offset 6
Ohgodwhy didn't I find dynamic earlier?! Nice one! You should promote this more; maybe editing the Wiki accordingly?
Since I didn't used it in the wild: what is your feeling using this in high-performance-critical plugins such as looping through all players in OnGameFrame and doing some extensive lookup & storage operations? Do you have experience with that?
It is safe as long as the Dynamic instances dont contain thousands of members.
My general rule is. If you access the data lots, use smaller member sets and Dynamic classes.
Dynamic classes store offsets which give a performance bump.