September 23, 2019, 06:57:10 AM

Author Topic: Is it bad practice to...  (Read 944 times)

Offline ErikT

  • Jr. Member
  • **
  • Posts: 13
Is it bad practice to...
« on: July 13, 2017, 11:23:00 AM »
... use the clipboard to transfer information between programs? I'm making a small program to allow nw.js (browser wrapped) games to switch resolutions, and the only means I know of to make nw.js communicate with the outside world is to write to the clipboard.

Offline markcwm

  • Sr. Member
  • ****
  • Posts: 400
Re: Is it bad practice to...
« Reply #1 on: July 13, 2017, 04:32:51 PM »
Yes clipboard could be wiped and it's just better not to do hacks, sending data by http to a server is a good idea but it seems you can save data to disk with Node-Webkit

https://www.scirra.com/tutorials/4870/save-and-load-game-in-a-specific-folder-using-nwjs-node-webkit

Offline ErikT

  • Jr. Member
  • **
  • Posts: 13
Re: Is it bad practice to...
« Reply #2 on: July 13, 2017, 05:03:04 PM »
Ah yih that's right, writing to disk is an option :) Clipboard is faster tho, and I figured if I just stored the previous clipboard content in memory and restored the clipboard whenever nwjs isn't writing to it it'd be okay.

But now I got some kind of memory leak on my hands so maybe I need to stick with writing to disk anyway.

Offline ErikT

  • Jr. Member
  • **
  • Posts: 13
Re: Is it bad practice to...
« Reply #3 on: July 13, 2017, 06:40:40 PM »
Is there any particular reason why this loop here would cause a memory leak?
Code: [Select]
While ProcessStatus(GameProcess) <> 0
ClipText=TextFromClipboard()

If ClipText = "nwjsLoaded"
If GraphicsModeExists(1366,768,0,0) And (1366 <> DesktopWidth() Or 768 <> DesktopHeight())
ChangeDisplayMode(1366,768,DesktopDepth(),DesktopHertz ())
EndIf
EmptyClipboard()
EndIf
Wend

EDIT:
Okay I think I got it sorted.

Offline xlsior

  • Jr. Member
  • **
  • Posts: 33
Re: Is it bad practice to...
« Reply #4 on: July 13, 2017, 08:45:32 PM »
Just one somewhat unrelated word of advice: You're explicitly checking for 1366x768, but be aware that there's quite a few laptops that don't support 1366x768 but will do 1360x768, which may be 'close enough' to allow as well?

Offline ErikT

  • Jr. Member
  • **
  • Posts: 13
Re: Is it bad practice to...
« Reply #5 on: July 13, 2017, 08:51:41 PM »
Yep no worries :) I'm already checking against a list of available resolutions in the full program. This was just to track down the leak.