SyntaxBomb - Indie Coders

General Category => General Discussion => Topic started by: ErikT on July 13, 2017, 11:23:00 AM

Title: Is it bad practice to...
Post by: ErikT 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.
Title: Re: Is it bad practice to...
Post by: markcwm 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
Title: Re: Is it bad practice to...
Post by: ErikT 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.
Title: Re: Is it bad practice to...
Post by: ErikT 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.
Title: Re: Is it bad practice to...
Post by: xlsior 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?
Title: Re: Is it bad practice to...
Post by: ErikT 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.
SimplePortal 2.3.6 © 2008-2014, SimplePortal