Getting Error when running Init() Topic is solved

Ask for help, how to use AHK_H, etc.
bennybroseph
Posts: 24
Joined: 03 Jul 2019, 10:00
Contact:

Getting Error when running Init()

04 Aug 2019, 17:05

error.png
error.png (14.4 KiB) Viewed 3707 times
So I'm not sure if this is related to AutoHotkey_H, but it's what I'm using. If I don't comment out Intercept.Init() then i get the above error.

InputManager.ahk

Code: Select all

class InputManager
{
	static s_Init := False

	static s_Moving 			:= False
	static s_ForceMouseUpdate	:= True

	static s_UsingReticule 			:= False
	static s_ForceReticuleUpdate 	:= True

	static s_MoveOnlyKey

	static s_RepeatForceMove
	static s_HaltMovementOnTarget

	static s_MouseOffset
	static s_TargetOffset

	static s_TargetedKeybinds
	static s_MovementKeybinds

	static s_PressStack
	static s_PressCount

	static s_LootDelay
	static s_TargetingDelay
	static s_HoldDelay

	static s_MovementRadius
	static s_TargetRadius

	static s_MousePos
	static s_TargetPos

	static s_MouseHidden

	static s_Cursor
	static s_Reticule

	Init()
	{
		InputManager.s_MoveOnlyKey := IniReader.ParseKeybind(IniReader.ReadKeybindingKey(KeybindingSection.Keybindings, "Force_Move"))

		InputManager.s_RepeatForceMove := IniReader.ReadProfileKey(ProfileSection.Preferences, "Repeat_Force_Move")
		InputManager.s_HaltMovementOnTarget := IniReader.ReadProfileKey(ProfileSection.Preferences, "Halt_Movement_On_Target")

		InputManager.s_MouseOffset
            := new Vector2(IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Movement_Center_Offset_X")
                        , IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Movement_Center_Offset_Y"))
        InputManager.s_TargetOffset
            := new Vector2(IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Targeting_Center_Offset_X")
                        , IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Targeting_Center_Offset_Y"))

		InputManager.s_TargetedKeybinds	:= IniReader.ParseKeybindArray("Targeted_Actions")
        InputManager.s_MovementKeybinds	:= IniReader.ParseKeybindArray("Movement_Actions")

		InputManager.s_PressStack := new LooseStack()
        InputManager.s_PressCount := new PressCounter()

		InputManager.s_LootDelay 		:= IniReader.ReadProfileKey(ProfileSection.Preferences, "Loot_Delay")
		InputManager.s_TargetingDelay	:= IniReader.ReadProfileKey(ProfileSection.Preferences, "Targeting_Delay")
		InputManager.s_HoldDelay 		:= IniReader.ReadProfileKey(ProfileSection.Preferences, "Hold_Delay")

		InputManager.s_MovementRadius
			:= new Rect(new Vector2(IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Movement_Min_Radius_Width")
								, IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Movement_Min_Radius_Height"))
					, new Vector2(IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Movement_Max_Radius_Width")
								, IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Movement_Max_Radius_Height")))

		InputManager.s_TargetRadius
			:= new Rect(new Vector2(IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Targeting_Min_Radius_Width")
								, IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Targeting_Min_Radius_Height"))
					, new Vector2(IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Targeting_Max_Radius_Width")
								, IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Targeting_Max_Radius_Height")))

		InputManager.s_MousePos		:= InputHelper.GetMousePos()
		;InputManager.s_TargetPos	:= CriticalObject(InputHelper.GetMousePos())

		InputManager.s_MouseHidden := True

		InputManager.s_Cursor 	:= new Image("Images\diabloCursor.png")
		InputManager.s_Reticule := new Image("Images\Target.png")

		;this.ChildInit()

		InputManager.s_Init := True
	}
	; Create accessors for children
	m_Init[] {
		get {
			return InputManager.s_Init
		}
	}

	m_Moving[] {
		get {
			return InputManager.s_Moving
		}
	}
	m_ForceMouseUpdate[] {
		get {
			return InputManager.s_ForceMouseUpdate
		}
	}

	m_UsingReticule[] {
		get {
			return InputManager.s_UsingReticule
		}
	}
	m_ForceReticuleUpdate[]	{
		get {
			return InputManager.s_ForceReticuleUpdate
		}
	}

	m_MoveOnlyKey[]	{
		get {
			return InputManager.s_MoveOnlyKey
		}
	}

	m_RepeatForceMove[]	{
		get {
			return InputManager.s_RepeatForceMove
		}
	}

	m_HaltMovementOnTarget[] {
		get {
			return InputManager.s_HaltMovementOnTarget
		}
	}

	m_MouseOffset[]	{
		get {
			return InputManager.s_MouseOffset
		}
	}
	m_TargetOffset[] {
		get {
			return InputManager.s_TargetOffset
		}
	}

	m_TargetedKeybinds[] {
		get {
			return InputManager.s_TargetedKeybinds
		}
	}
	m_MovementKeybinds[] {
		get {
			return InputManager.s_MovementKeybinds
		}
	}

	m_PressStack[] {
		get {
			return InputManager.s_PressStack
		}
	}
	m_PressCount[] {
		get {
			return InputManager.s_PressCount
		}
	}

	m_LootDelay[] {
		get {
			return InputManager.s_LootDelay
		}
	}
	m_TargetingDelay[] {
		get {
			return InputManager.s_TargetingDelay
		}
	}
	m_HoldDelay[] {
		get {
			return InputManager.s_HoldDelay
		}
	}

	m_MovementRadius[] {
		get {
			return InputManager.s_MovementRadius
		}
	}
	m_TargetRadius[] {
		get {
			return InputManager.s_TargetRadius
		}
	}

	m_MousePos[] {
		get {
			return InputManager.s_MousePos
		}
		set {
			return InputManager.s_MousePos := value
		}
	}
	m_TargetPos[] {
		get {
			return InputManager.s_TargetPos
		}
		set {
			return InputManager.s_TargetPos := value
		}
	}

	m_MouseHidden[] {
		get {
			return InputManager.s_MouseHidden
		}
	}

	m_Cursor[] {
		get {
			return InputManager.s_Cursor
		}
	}
	m_Reticule[] {
		get {
			return InputManager.s_Reticule
		}
	}

	ChildInit() {
	}
}
Intercept.ahk

Code: Select all

; Intercepts keyboard and mouse input and manipulates it

class Intercept extends InputManager
{
	static m_Up 	:= False
	static m_Down 	:= False
	static m_Left 	:= False
	static m_Right 	:= False

	static m_PrevMovement := new Vector2()
	static m_Movement := new Vector2()

	static m_Reticule

	ChildInit()
	{
		global

		BlockInput, MouseMove

		this.m_Reticule := new Image("Images\Target.png")

		; TODO Loop through movement inputs

		; Up inputs
		local fn := ObjBindMethod(Intercept, "MovePress", "Up")
		hotkey, $w, % fn
		local fn := ObjBindMethod(Intercept, "MoveRelease", "Up")
		hotkey, $w Up, % fn

		; Down inputs
		local fn := ObjBindMethod(Intercept, "MovePress", "Down")
		hotkey, $s, % fn
		local fn := ObjBindMethod(Intercept, "MoveRelease", "Down")
		hotkey, $s Up, % fn

		; Left inputs
		local fn := ObjBindMethod(Intercept, "MovePress", "Left")
		hotkey, $a, % fn
		local fn := ObjBindMethod(Intercept, "MoveRelease", "Left")
		hotkey, $a Up, % fn

		; Right Inputs
		local fn := ObjBindMethod(Intercept, "MovePress", "Right")
		hotkey, $d, % fn
		local fn := ObjBindMethod(Intercept, "MoveRelease", "Right")
		hotkey, $d Up, % fn

		; TODO Loop through Targeted Skills
		local _keybind := IniReader.ParseKeybind("q")
		_keybind.Type := KeybindType.Targeted

		local fn := ObjBindMethod(Intercept, "TargetedPress", _keybind)
		hotkey, $q, % fn
		local fn := ObjBindMethod(Intercept, "TargetedRelease", _keybind)
		hotkey, $q Up, % fn

		local fn := ObjBindMethod(Intercept, "TargetedPress", IniReader.ParseKeybind("LButton"))
		hotkey, $LButton, % fn
		local fn := ObjBindMethod(Intercept, "TargetedRelease", IniReader.ParseKeybind("LButton"))
		hotkey, $LButton Up, % fn

		local fn := ObjBindMethod(Intercept, "TargetedPress", IniReader.ParseKeybind("Shift+LButton"))
		hotkey, $+LButton, % fn
		local fn := ObjBindMethod(Intercept, "TargetedRelease", IniReader.ParseKeybind("Shift+LButton"))
		hotkey, $+LButton Up, % fn

		local fn := ObjBindMethod(Intercept, "TargetedPress", IniReader.ParseKeybind("RButton"))
		hotkey, $RButton, % fn
		local fn := ObjBindMethod(Intercept, "TargetedRelease", IniReader.ParseKeybind("RButton"))
		hotkey, $RButton Up, % fn

		AHKThread("
		(
			#Include Input\MouseThread.ahk
		)", &this.m_TargetPos "")

		this.m_CurrTime := FPS.GetCurrentTime()
		this.m_PrevTime := this.m_CurrTime

		Debug.OnToolTipAddListener(new Delegate(Intercept, "OnToolTip"))
	}

	Update()
	{
		global

		this.m_PrevMovement := this.m_Movement.Clone()

		this.m_Movement := new Vector2()
		if (this.m_Up)
			this.m_Movement.Y -= 1
		if (this.m_Down)
			this.m_Movement.Y += 1

		if (this.m_Left)
			this.m_Movement.X -= 1.5
		if (this.m_Right)
			this.m_Movement.X += 1.5

		if (!Vector2.IsEqual(this.m_Movement, this.m_PrevMovement))
		{
			local _centerOffset
				:= Vector2.Add(Vector2.Add(Graphics.ActiveWinStats.Pos, Graphics.ActiveWinStats.Center)
							, Vector2.Mul(this.m_MouseOffset, Graphics.ResolutionScale))

			InputHelper.MoveMouse(Vector2.Add(_centerOffset, Vector2.Mul(this.m_Movement, 50)))
			if (!Vector2.IsEqual(this.m_Movement, Vector2.Zero))
				InputHelper.PressKeybind(this.m_MoveOnlyKey)
			else
				InputHelper.ReleaseKeybind(this.m_MoveOnlyKey)
		}

		this.m_Reticule.Draw(this.m_TargetPos)
	}

	TargetedPress(p_Keybind)
	{
		InputHelper.PressKeybind(p_Keybind)
	}
	TargetedRelease(p_Keybind)
	{
		InputHelper.ReleaseKeybind(p_Keybind)
	}

	MovePress(p_Direction)
	{
		if (p_Direction = "Up")
			this.m_Up := True
		if (p_Direction = "Down")
			this.m_Down := True
		if (p_Direction = "Left")
			this.m_Left := True
		if (p_Direction = "Right")
			this.m_Right := True
	}
	MoveRelease(p_Direction)
	{
		if (p_Direction = "Up")
			this.m_Up := False
		if (p_Direction = "Down")
			this.m_Down := False
		if (p_Direction = "Left")
			this.m_Left := False
		if (p_Direction = "Right")
			this.m_Right := False
	}

	; MouseEvent(p_MouseID, p_X := 0, p_Y := 0)
	; {
	; 	global

	; 	static _carryX := 0, _carryY := 0, _mainMouse

	; 	if (p_MouseID = 0 or (_mainMouse and p_MouseID != _mainMouse))
	; 		return

	; 	_mainMouse := p_MouseID

	; 	this.m_PrevTime := this.m_CurrTime
	; 	this.m_CurrTime := FPS.GetCurrentTime()

	; 	local _deltaTime := Min(this.m_CurrTime - this.m_PrevTime, FPS.Delay)

	; 	; Pre-scale
	; 	p_X *= 3
	; 	p_Y *= 3

	; 	; Speedcap
	; 	if (False)
	; 	{
	; 		local _rate := Sqrt(p_X * p_X + p_Y * p_Y)

	; 		if (_rate >= 10)
	; 		{

	; 		}
	; 	}

	; 	; Acceleration
	; 	local _accelSens := 1
	; 	if (True)
	; 	{
	; 		local _rate := Sqrt(p_X * p_X + p_Y * p_Y) / _deltaTime
	; 		_rate -= 1

	; 		if (_rate > 0)
	; 		{
	; 			_rate *= 1.5

	; 			local _power = Max(2 - 1, 0)
	; 			_accelSens += Exp(_power * Log(_rate))
	; 		}
	; 	}
	; 	_accelSens /= 1

	; 	p_X *= _accelSens
	; 	p_Y *= _accelSens

	; 	p_X *= _deltaTime / 1000
	; 	p_Y *= _deltaTime / 1000

	; 	p_X *= 50
	; 	p_Y *= 50

	; 	this.m_DeltaMouse := new Vector2(p_X, p_Y)

	; 	this.m_CursorPos := Vector2.Add(this.m_CursorPos, this.m_DeltaMouse)
	; 	this.m_Reticule.Draw(this.m_CursorPos)
	; }

	OnToolTip()
	{
		global

		local _debugText :=

		_debugText .= "CursorPos: " . this.m_TargetPos.String . " Movement" . this.m_Movement.String

		return _debugText
	}
}
MouseThread.ahk

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance Force
;#Persistent  ; Keep this script running until the user explicitly exits it.

#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#MaxThreads 255

#KeyHistory 0

ListLines Off

Process, Priority, , A
SetBatchLines, -1

#Include Library\MouseDelta.ahk
#Include Library\Delegate.ahk

_critObj := CriticalObject(A_Args[1])

_function := new MouseDelta(new Delegate("MouseEvent"))
_function.SetState(1)

return

MouseEvent(p_MouseID, p_X := 0, p_Y := 0)
{
	global

	static _carryX := 0, _carryY := 0, _mainMouse

	if (p_MouseID = 0 or (_mainMouse and p_MouseID != _mainMouse))
		return

	_mainMouse := p_MouseID

	_critObj.X += p_X
	_critObj.Y += p_Y
}
I just tried using threads today, so I'm sure what I'm attempting to do is extremely wrong.
The second part that is probably causing problems is the fact that I'm extending from InputManager. I do this because there is another class 'Controller.ahk' which is disabled right now but will be reading from the same static values and also extends from InputManager.

The goal is to have a separate thread receive raw mouse input and send it back to the main thread. That way I can BlockInput, MouseMove while still processing mouse input.

This is part of a larger project which converts joystick input to mouse and keyboard macros. This new bit is to change WASD to mouse input while having a software cursor act as a sort of targeting reticule for other keyboard actions which need the mouse to function.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Getting Error when running Init()

04 Aug 2019, 17:53

the error points to line 2k whatever in gdip.ahk
its probably trying to fiddle with a shared resource it has no access to/hasnt locked
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Getting Error when running Init()

04 Aug 2019, 18:25

As far as I remember it was not easy to find the problem in GDip, simply disable #WarnContinuableException: http://hotkeyit.github.io/v2/docs/commands/_WarnContinuableException.htm
bennybroseph
Posts: 24
Joined: 03 Jul 2019, 10:00
Contact:

Re: Getting Error when running Init()  Topic is solved

04 Aug 2019, 18:36

Thank you for the reply guys! The issue was resolved when I realized Init() was being called twice accidentally by both Controller.ahk and Intercept.ahk. However, I may very well run into an actual issue with GDip in the future as even with Init() being called twice it didn't make much sense as to why that specific error would occur. I will keep in mind what you said.

Return to “Ask for Help”

Who is online

Users browsing this forum: No registered users and 17 guests