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

API Hawk: MemoryDomains specified with attribute [RequiredService] will throw NullReferenceException when loading external tool DLL with EmuHawk using argument --open-ext-tool-dll . #3329

Closed
tommai78101 opened this issue Jul 23, 2022 · 1 comment
Labels
App: EmuHawk Relating to EmuHawk frontend Repro: Fixed/added in 2.9 Reproducible bug Should only be added to issues with a `Repro: Affects` label.

Comments

@tommai78101
Copy link
Contributor

Summary

When developing a DLL external tool project for BizHawk, if the tool needs to use MemoryDomains, it will throw a null pointer reference exception when the DLL is loaded by passing the argument --open-ext-tool-dll to EmuHawk.exe.

I did make sure to include this in my WinForm class:

		[RequiredService]
		public IEmulator Emulator { get; set; }

		[RequiredService]
		public IMemoryDomains MemoryDomains { get; set; }

And I also added this in the this.Load event from MainForm to bind a System.EventHandler delegate to this method:

		public void OnBotLoad(object sender, EventArgs eventArgs) {
			if (!CurrentMovie.IsActive() && !Tools.IsLoaded<TAStudio>()) {
				DialogController.ShowMessageBox("In order to proceed to use this tool, TAStudio is required to be opened.");
				this.Close();
				DialogResult = DialogResult.Cancel;
				return;
			}

			if (Config!.OpposingDirPolicy is not OpposingDirPolicy.Allow) {
				DialogController.ShowMessageBox("In order to proceed to use this tool, please check if the U+D/L+R controller binds policy is set to 'Allow'.");
				this.Close();
				DialogResult = DialogResult.Cancel;
				return;
			}

			if (OSTailoredCode.IsUnixHost) {
				ClientSize = new(707, 587);
			}

			_previousInvisibleEmulation = InvisibleEmulationCheckBox.Checked = Settings.InvisibleEmulation;
			_previousDisplayMessage = Config.DisplayMessages;
		}

Repro

  1. Either pull down the commit here (commit ID: 23f8f660), or download the attachment below.

tool_src.zip

  1. Build the DLL.
  2. Follow the instructions from the Quick Development guide (here) to load the DLL via EmuHawk.
  3. You should be able to see an exception thrown mentioning the MemoryDomains encountering a null pointer reference.

If not, you can try "Debugging a DLL using external application" and attaching the debugger to the application, by following this instruction from Microsoft:

https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-debug-from-a-dll-project?view=vs-2022#specify-a-calling-app-in-a-c-dll-project-net-core-net-5

Output

These exceptions all point to the same thing.

Pictures are only here to help:

image
image

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=GeneticAlgorithmBot
  StackTrace:
   at GeneticAlgorithmBot.GeneticAlgorithmBot.Restart() in E:\LargeGithubProjects\Bizhawk-GeneticAlgorithmBot\src\GeneticAlgorithmBot.cs:line 266
System.NullReferenceException: Object reference not set to an instance of an object.
   at GeneticAlgorithmBot.GeneticAlgorithmBot.Restart()
   at BizHawk.Client.EmuHawk.ToolManager.LoadExternalToolForm(String toolPath, String customFormTypeName, Boolean focus, Boolean skipExtToolWarning)
   at BizHawk.Client.EmuHawk.MainForm.MainForm_Load(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at BizHawk.Client.EmuHawk.FormBase.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at BizHawk.Client.EmuHawk.MainForm.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Host env.

  • BizHawk dev build at 84886b7; Win10 Pro 21H1; Intel/NVIDIA
@tommai78101 tommai78101 changed the title API Hawk: MemoryDomains specified with attribute [RequiredService] will throw NullPointerReferenceException when loading external tool DLL with EmuHawk using argument --open-ext-tool-dll . API Hawk: MemoryDomains specified with attribute [RequiredService] will throw NullReferenceException when loading external tool DLL with EmuHawk using argument --open-ext-tool-dll . Jul 23, 2022
@YoshiRulz
Copy link
Member

IToolForm.Restart is called from two places; on init, and when restarting all tools. Only the latter checks services are available.

@YoshiRulz YoshiRulz added the App: EmuHawk Relating to EmuHawk frontend label Jul 23, 2022
@YoshiRulz YoshiRulz self-assigned this Jul 23, 2022
@YoshiRulz YoshiRulz removed their assignment Jul 25, 2022
@YoshiRulz YoshiRulz added Reproducible bug Should only be added to issues with a `Repro: Affects` label. Repro: Fixed/added in 2.9 labels Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
App: EmuHawk Relating to EmuHawk frontend Repro: Fixed/added in 2.9 Reproducible bug Should only be added to issues with a `Repro: Affects` label.
Projects
None yet
Development

No branches or pull requests

2 participants