Is it bad practice to...

Started by ErikT, July 13, 2017, 11:23:00

Previous topic - Next topic

ErikT

... 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.

markcwm

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

ErikT

#2
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.

ErikT

#3
Is there any particular reason why this loop here would cause a memory leak?

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.

xlsior

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?

ErikT

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.