Raised This Month: $32 Target: $400
 8% 

Dynamic Objects and Properties - v.0.0.32 - [2018.05.08]


Post New Thread Reply   
 
Thread Tools Display Modes
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 02-27-2017 , 10:00   Re: Dynamic Objects and Properties - v.0.0.24 - [2017.02.11]
Reply With Quote #221

Thanks for your quick reply.

Quote:
Originally Posted by Neuro Toxin View Post
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 View Post
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 View Post
KeyValues operations are currently only supported on real Dynamic objects.
Ah ok, thanks for clarifying this.

Last edited by SM9; 02-27-2017 at 10:04.
SM9 is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 02-27-2017 , 16:58   Re: Dynamic Objects and Properties - v.0.0.24 - [2017.02.11]
Reply With Quote #222

Quote:
Originally Posted by xCoderx View Post
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?.
https://github.com/ntoxin66/Dynamic/...ection.inc#L41

Quote:
Originally Posted by xCoderx View Post
I was thinking about maybe showing the contents of the objects too, but I don't want to make too much work for you
I normally .WriteKeyValues to check my structure.

Make sure you have the latest version also. There was a bug in collections causing corruption and leaks.
__________________

Last edited by Neuro Toxin; 02-27-2017 at 19:14.
Neuro Toxin is offline
jdlovins
Junior Member
Join Date: Sep 2015
Old 03-03-2017 , 23:04   Re: Dynamic Objects and Properties - v.0.0.24 - [2017.02.11]
Reply With Quote #223

I seem to be running into a very weird issue.

I have a test plugin like this

Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR ""
#define PLUGIN_VERSION "0.00"

#include <sourcemod>
#include <sdktools>

#pragma newdecls required

#include <dynamic>
#include <testdyn>

public Plugin myinfo = 
{
	name = "",
	author = PLUGIN_AUTHOR,
	description = "",
	version = PLUGIN_VERSION,
	url = ""
};

public void OnPluginStart()
{
	TestDyn t = TestDyn();
	t.time = 5.5;
	t.Dispose();
}
and a methodmap dynamic class

Code:
#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
jdlovins is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-04-2017 , 05:18   Re: Dynamic Objects and Properties - v.0.0.24 - [2017.02.11]
Reply With Quote #224

Make sure you have the latest version of dynamic.

https://github.com/ntoxin66/Dynamic/releases

1. Does the problem persist?
2. Do you compile warnings?
__________________
Neuro Toxin is offline
jdlovins
Junior Member
Join Date: Sep 2015
Old 03-04-2017 , 10:26   Re: Dynamic Objects and Properties - v.0.0.24 - [2017.02.11]
Reply With Quote #225

Quote:
Originally Posted by Neuro Toxin View Post
Make sure you have the latest version of dynamic.

https://github.com/ntoxin66/Dynamic/releases

1. Does the problem persist?
2. Do you compile warnings?
I am also using the latest version of that and sourcemod. I tried updating sourcemod hoping that would fix it but it didn't

Yeah it persists even when I reload the plugin and even when I restart srcds. I even tried it on a completely different vps and it still happened.

No compiling warnings. Everything seems good. Any other variable type works like ints and such.

edit:

running the garbage collect method gets me

Code:
sm_dynamic_collectgarbage
Dynamic is starting it's garbage collector...
L 03/04/2017 - 10:27:12: [SM] Exception reported: Could not read Handle 51e40d20 (error 3)
L 03/04/2017 - 10:27:12: [SM] Blaming: dynamic.smx
L 03/04/2017 - 10:27:12: [SM] Call stack trace:
L 03/04/2017 - 10:27:12: [SM]   [0] GetPluginStatus
L 03/04/2017 - 10:27:12: [SM]   [1] Line 246, ..\dynamic.sp::_Dynamic_CollectGarbage
L 03/04/2017 - 10:27:12: [SM]   [2] Line 49, ..\dynamic/system/commands.sp::OnDynamicCollectGarbageCommand
I tried messing around with the gc stuff more and found something sort of interesting...

I have a plugin that just creates a dyanmic methodmap on plugin start

TestDyn t = TestDyn();

Code:
[SM] Plugin testdyn.smx reloaded successfully.

sm_dynamic_handles
Dynamic is running a HandleUsage report...
-> Total Handles: 1 (0 persistant handles)
--> ``: 1 Handles (0 persistant handles)

sm_dynamic_collectgarbage
Dynamic is starting it's garbage collector...

sm_dynamic_handles
Dynamic is running a HandleUsage report...
-> Total Handles: 1 (0 persistant handles)
--> ``: 1 Handles (0 persistant handles)


sm_dynamic_collectgarbage
Dynamic is starting it's garbage collector...
sm_dynamic_collectgarbage
Dynamic is starting it's garbage collector...

sm_dynamic_handles
Dynamic is running a HandleUsage report...
-> Total Handles: 1 (0 persistant handles)
--> ``: 1 Handles (0 persistant handles)
Doesn't seem to be able to clear out these methodmaps.

edit 2:

just tried doing -insecure with a local SM running on tf2 and it also happens. the same index at 65. Something is odd.

Last edited by jdlovins; 03-04-2017 at 16:39.
jdlovins is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-05-2017 , 03:02   Re: Dynamic Objects and Properties - v.0.0.24 - [2017.02.11]
Reply With Quote #226

You are responsible to .Dispose each Dynamic instance you create.

Edit: The Dynamic Lifecycle
__________________

Last edited by Neuro Toxin; 03-05-2017 at 03:04.
Neuro Toxin is offline
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 03-05-2017 , 08:03   Re: Dynamic Objects and Properties - v.0.0.24 - [2017.02.11]
Reply With Quote #227

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?
Chrisber is offline
jdlovins
Junior Member
Join Date: Sep 2015
Old 03-05-2017 , 11:24   Re: Dynamic Objects and Properties - v.0.0.24 - [2017.02.11]
Reply With Quote #228

Quote:
Originally Posted by Neuro Toxin View Post
You are responsible to .Dispose each Dynamic instance you create.

Edit: The Dynamic Lifecycle
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


Okay. everything looks normal.

I have a plugin that does
Code:
public void OnPluginStart()
{
	MyClass mc = MyClass();
	mc.int1 = 3;
	mc.int2 = 4;
	mc.bool1 = false;
	mc.float1 = 2.1;
	mc.Dispose();
}
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


It's trying to access position 0 for the ints and bools. Then it gets to the float and uses position 65 ( the right position i believe. )

Am i misunderstanding something or is there actually a big bug?

edit 3:

sorry for the long post. Just kinda going as i look through stuff. I believe i found the issue.

Code:
stock bool _Dynamic_SetFloatByOffset(DynamicObject dynamic, DynamicOffset offset, float value)
{
	if (!dynamic.IsValid(true))
		return false;
	
	Dynamic_MemberType type = _SetFloat(dynamic.Data, dynamic.Index, offset.Cell, dynamic.BlockSize, value);
	_Dynamic_CallOnChangedForwardByOffset(dynamic, offset, type);
	return true;
}
This uses dynamic.Index

Now look at

Code:
stock bool _Dynamic_SetIntByOffset(DynamicObject dynamic, DynamicOffset offset, int value)
{
	if (!dynamic.IsValid(true))
		return false;
	
	Dynamic_MemberType type = _SetInt(dynamic.Data, offset.Index, offset.Cell, dynamic.BlockSize, value);
	_Dynamic_CallOnChangedForwardByOffset(dynamic, offset, type);
	return true;
}
this uses offset.Index

The same goes for bool, it uses offset.Index.

I dont know which one is the right one and which one is the wrong one. offset.Index or dynamic.Index. I want to say its dynamic but I'm not too sure.

Changing float to use offset.Index fixes the float problem.

I guess it happened here; https://github.com/ntoxin66/Dynamic/...1cfe7d5c2cR118

Last edited by jdlovins; 03-05-2017 at 13:10.
jdlovins is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-05-2017 , 16:39   Re: Dynamic Objects and Properties - v.0.0.24 - [2017.02.11]
Reply With Quote #229

Quote:
Originally Posted by Chrisber View Post
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.
__________________
Neuro Toxin is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-05-2017 , 17:29   Re: Dynamic Objects and Properties - v.0.0.24 - [2017.02.11]
Reply With Quote #230

@ jdlovins

I'll look into what you've said.

I will iterate you MUST dispose your dynamic objects.
__________________
Neuro Toxin is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:02.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode