libGDX setCursorCatched and simple config bug - libgdx

I'm trying to figure out some very odd behavior in libGDX right now. Take the following simple application code as an example.
package com.station40.desktop;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.station40.Station40;
public class DesktopLauncher {
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.width = 800;
config.height = 600;
LwjglApplication app = new LwjglApplication(new Station40(), config);
Gdx.input.setCursorCatched(true);
}
}
Simple enough. I encounter 2 consistent problems with this though:
When the cursor is actually "catched", invisible and impossible to move, the javaw process appears to freeze. The CPU usage sticks to 1 whole processor. Similar code to above stops executing normal frame updates with no other changes besides setCursorCatch(true) was called. What is happening here? Have I done something wrong?
Annoyingly, when launched from Eclipse, the application ignores the config completely; every time I run an application it will open in a tiny window like so: http://i.imgur.com/cK1dwMR.png. The first time I ran this application, it opened fine at 800x600. Since then, it reverted (like all the other before it) to this tiny window. For reference, fullscreen completely fails: I get a resolution change but I see no window. My mouse is even caught.
Has anyone encountered these issues before? I've setup using the Gradle setup as described on the wiki. I've been using libGDX a long time and never had these issues until now. Any help would be greatly appreciated.

Let this be a lesson to update ALL versions of a library. Or, better yet, keep only one copy! My old libGDX utility project was importing an older version of libGDX while new ones, using the Gradle system, imported the new ones. The two did not mesh well and caused all of the listed problems.
I moved the old utility project into a new Gradle-managed project and things are working better now.
For those wondering, this was because lwjgl expects a certain buffer of ints for window size to be in (top, bottom, left, right) order in one version and (top, left, bottom, right) order in another. I expect it disliked the resulting 0-height, negative-width window!

Related

Exception Breakpoint fires when copying View Controller between projects

I've customized a tutorial and am trying to import it into my project. After copying one View Controller Scene from Document Outline into my main project, it's throwing an exception without any description of the issue. The View Controller is subclassed, so I've made sure to import the associated Swift file and set it in Document Attributes.
I don't know how to troubleshoot this one.
===EDIT===
I'm at a total loss here. I created a new project and was able to import, build, and run the project. The only difference between my main project and the new one is the VC is not the initial View Controller.
The tuturial was written in XCode 11 and Swift 4. I haven't upgraded yet, but again I was able to import into a new project w/o issue.
Check the Connections inspector (the last option on the right sidebar) and make sure there are no connections with exclamation marks (!) after them.
If there are errors, check in the Identity inspector (the third option from the left on the right sidebar) if the class of the view controller is correct.
If the connections are not needed anymore (you gave the outlet a new name etc.), remove them by clicking on the X next to them.

LibGDX: Gwt logging not working in my project

Don't worry, I'm not asking you to fix all my bugs, I just wanted to know common causes for gwt/html logging to not work.
Here is my project:
https://github.com/vedi0boy/Archipelo
I cannot get logging to work at all in html. I used this code in a brand new LibGDX project and it worked (inside the main class):
#Override
public void create () {
Gdx.App.setLogLevel(Application.LOG_DEBUG);
Gdx.app.log("Test", "Test log message.";
}
I just don't get it. Is there something common that could be making basic html/gwt functions not work? My libgdx is update to 1.9.2. I can't seem to figure out why it works on a new project but not mine.
What should I do? Should I attempt to copy all the code to a new project? Thanks.
P.S. I am also unable to use a networking library that I need, and it also works on a brand new project.
The solution was simple. I made a while loop that did not continue until a connection to the server was established. Since javascript is single threaded, it got caught in an infinite loop.
The reason this has to do with logging is because LibGDX only loads up the log box when create is finished being run and my infinite loop was in create so it never got around to rendering the logs.
Lesson: Don't treat JavaScript as a multi-threaded language when using GWT, because it isn't.
You don't need to copy all your code to a new project, if you have doubts about your LIBGDX version you can update your corruent project to a recent V of libgdx,
use the build.gradle like follow :
gdxVersion = "1.5.2" // your gdx version here
for more info read this topic in the official WIKI

Flash Professional CC stuck on publishing swf from huge .fla

My .fla is about 600mb big due to enormous amount of library objects.
I have 15.500 objects in library and most of them are images. This is probably bad practice, but my client required to have these images inside of it instead of loading them dynamically from some external source.
I have already reduced the size of the images as much as possible while still maintaining good quality.
I'm publishing for Flash Player, and already tried different versions.
Basicly my app is fairly simple test paper app, populating 20 test papers with simple multiple choise questions. Each test paper has 150 questions divided into 4 sections, and each question contains 1 question image and 4 answer images to choose from. After user picks his/her answer, these image instances are being deleted and new ones are being created.
I've heard that there's magical limit of 16.000 for everything like instances and so on, so it should stay right about under it as the code itself is quite simple and there's not many other instances after these images.
Besides my ugly file size, I'm also pushing all these images from library into arrays in a loop:
(linkage names are for example "Paper1_Chem_Q1_C.jpg", and "_X" marks the correct answer - that's why I unshift that one)
var sectionLengths:Array = [40,40,45,25];
var prefixes:Array = ["Phys","Chem","Maths","Eng_Reas"];
var prefixes2:Array = ["A","B","C","D"];
for(var p:int = 0; p<20; p++){ //test papers loop
for(var s:int = 0; s<4; s++){ //sections loop
var fillQArray:Array = this["tp"+(p+1)+"section"+(s+1)+"questions"];
var fillAArray:Array = this["tp"+(p+1)+"section"+(s+1)+"answers"];
for(var q:int = 0; q<sectionLengths[s]; q++){ //question loop
if(ApplicationDomain.currentDomain.hasDefinition(String("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)))){
fillQArray.push(getDefinitionByName("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)) as Class);
var qa:Array = new Array();
for(var a:int = 0; a<4; a++){ //answers loop
if(ApplicationDomain.currentDomain.hasDefinition(String("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)+"_"+prefixes2[a]))){
qa.push(getDefinitionByName("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)+"_"+prefixes2[a]));
}else if(ApplicationDomain.currentDomain.hasDefinition(String("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)+"_"+prefixes2[a]+"_X"))){
qa.unshift(getDefinitionByName("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)+"_"+prefixes2[a]+"_X"));
}
}
fillAArray.push(qa);
}
}
}
}
This loop surely does the job, but takes some time to run. Also, I predefine a LOT of arrays before it, so can this be another potential issue?
During development I've tested everything with few test papers, and it all worked like a charm, but now when I imported all the rest of the images, it gets stuck on publish. I left it to publish for the whole night, but now at morning it's once again stuck and I have to kill Flash process in order to quit it.
I have also increased memory amount from jvm.ini already to 2048m, so it doesn't give anymore the warning dialog regarding to too small JVM memory.
All suggestions are more than welcome.
I finally got it working, thanks to Vesper!
Here's detailed instructions for Flash Professional CC (so detailed becouse this was all new to me, and I spent almost 2 days for this failing multiple times):
Step 1 - Publish SWC:
Create empty .fla and import your images to library. Select all the
images and open properties with mouse2 button. At ActionScript tab
select Export for ActionScript. Make sure that also Export in frame 1 is activated.
Define a Classname for your project at Properties panel, for example: images_swc.
Go to Publish Settings and publish only SWC.
Notes:
In my case I had to create 3 SWC files becouse of the amount of images (15000+).
While adding/removing large amount of images to/from library, and while publishing a SWC, Flash Professional stopped responding and it looked like a crash, but in 30-60mins it succesfully finished!
When it was over an hour in "not responding" -state, I killed Flash process and tried with smaller amount of images.
First I created my "empty" .fla by removing everything but images from my main project, but somehow it didn't export correct images during SWC publish. But after I Saved As.. my image project, it worked like a charm.
Always when Flash notified about low JVM memory, I doubled the memory value in jvm.ini and started over. (Had eventually 4096m.)
Step 2 - Use SWC in your main project:
File -> Publish Settings -> Advanced ActionScript 3.0 Settings (wrench -icon at top-right-corner) -> Library path tab -> Click Browse to SWC file, locate your SWC and click OK.
Create empty .as file and type every image classname into it. Idea here is to mention all the images from SWC so that compiler understands that you want to include them in your main project. e.g:
package {
public class Assets {
image_1;
image_2;
image_3;
}
}
In your main project, include Assets.as and your SWC-file(s):
import Assets;
import images_swc;
Refer to your images with:
getDefinitionByName("image_1")
Final notes:
If you forget your "SWC classname", change the extension of your SWC file to .zip, open it, and you'll find your classname and other details from the xml file inside of it.
To get filenames of large amount of images for your .as file (assuming you have same classnames and filenames for your images), you can use windows command prompt and "dir /s > filename.txt" -command to gether filenames into txt-file. Myself I used free version of Directory List & Print which also finds files from subfolders, pasted the file list into Assets.as and used Find & Replace functionality in Flash to replace ".jpg" with ";".
So, I had over 15000 images, turned them into 3 SWC files = 15-20 megs per SWC, and my final .swf was around 55 megs - and it was compiled in couple minutes, which makes this pretty perfect solution for my project.
#Vesper, thanks again! :)

Active Desktop Website to Open Programs?

I have always thought that replacing the normal windows desktop icons with an "active desktop" html page which can launch my programs, as well as open directories and files through links. This would be a really cool way to customize one's desktop.
Using the "file://" protocal was my first approach but this does not work correctly. In another SO Post I found this link but its a little over my head. Is this the correct approach?
I can't imagine that I am the first one to consider this; it seems like a good idea (no?). What do you all think?
I like the idea of active desktop for a desktop customization. What you can do is register your own schema
Add a Registry entry.
Here is the first example I worked with.
Add This to a .reg file and Import into the registry.
Change "myschema" and the location of the executable to match your own needs
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\myschema]
#="URL:My Schema Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\myschema\DefaultIcon]
#="C:\\Program Files\\MySchemaProgram\\MySchema.exe,1"
[HKEY_CLASSES_ROOT\myschema\shell]
[HKEY_CLASSES_ROOT\myschema\shell\open]
[HKEY_CLASSES_ROOT\myschema\shell\open\command]
#="\"C:\\Program Files\\MySchemaProgram\\MySchema.exe\" \"%1\""
Now if you create a hyperlink
<a href="myschema://Whatever+i+want" >Click Here</a>
Your computer will open your MySchema Application with the href in the command line.
just be mindful because Ervironment.CommandLine will be UTF Decoded therefore
//This Link
Click Here
//Will Result in This Command Line Execution.
"C:\Program Files\MySchemaProgram\MySchema.exe" myschema://Something Here
You can also use this schema in the ShellExecute commands as well as the Run Dialog.
Here is the example program I used to get started with. You should be able to get the idea pretty quick
using System;
using System.Collections.Generic;
using System.Text;
namespace Alert
{
class Program
{
static string ProcessInput(string s)
{
// TODO Verify and validate the input
// string as appropriate for your application.
return s;
}
static void Main(string[] args)
{
Console.WriteLine("Alert.exe invoked with the following parameters.\r\n");
Console.WriteLine("Raw command-line: \n\t" + Environment.CommandLine);
Console.WriteLine("\n\nArguments:\n");
foreach (string s in args)
{
Console.WriteLine("\t" + ProcessInput(s));
}
Console.WriteLine("\nPress any key to continue...");
Console.ReadKey();
}
}
}
best of luck with your application. I would be eager to see it when it is complete.
EDIT: I am adding some matching strings for this as it is a cool feature and more people may want to use this technique for something they wanted to do.. These are the things i looked for it under, (unsuccessfully) Let me know if anyone thinks of any more.
custom url/uri handler
custom schema program
registry web address program
handle web link
launch app from url
I've looked into what you've asked a while back and never found anything that worked well.
Ultimately if the goal is full customization of your desktop, I think you can get a similar result by researching something like this: http://rainmeter.net/RainCMS/ and http://kaelri.deviantart.com/art/Enigma-103823591 Lifehacker has tons of links/tutorials on how to get it all running. I was able to get a desktop running that far exceeded my goals with using HTML on the desktop.
One way I got some really interesting results (though I haven't tried it for years and can't confirm right now that it still works on a modern OS and modern flash player) was to use an active desktop page running a flash swf file that contained a user interface I had created and (at the time I was using it) could launch programs from within the swf.
I ran a setup in a cyber cafe where each desktop was controlled via active desktop running a flash app. Launching and shutdown operations were handled with a mini webserver written in python. The OS was XP.
My experience was that Active Desktop is unreliable. It leaks memory terribly and regularly crashes. They might have fixed it in later versions but since hardly anyway uses it I doubt much effort has gone into fixing its obvious flakiness.

Flex Builder not building changes

I'm having a very strange bug in Flex Builder where none of the changes I make are appearing when I debug/run my program. It only happens with a particular AS3 project, on others, it works fine.
For example, I have a line,var x:int = this.prevX + this.x;, whose value is 400 if I don't make any changes. I change the line to var x:int = 0; and set a breakpoint on the line. When I debug the program, it breakpoints just where it should, but the value is set to 400, even when the line is x = 0! What gives!
I've tried cleaning the project and deleting the project and re-importing it. No matter what I do, it won't show any changes I make, even if I just toggle a boolean. It still won't let me compile with errors, but once its done compiling, it completely ignore whatever changes I made. It's like it has the bytecode for the swf cached somewhere and its just ignoring doing the actual build step.
Any ideas?
Check if you have a copy of the swf in the html-template folder. The newly compiled swf will be overwritten by that old one after each build. Happened to me once.
Right click the project in the Flex Navigator and then click Refresh. Refreshing the project worked for me.
Changing from IE to Chrome worked for me.
I was having trouble with this as well, and deleting the html-template folder didn't fix the problem for me. I then renamed the project and it worked after that.
I get this too.
This is the first time I've found this referenced on the net. It's a BIG problem. I get it periodically. For me, it's not the html-template folder.
I've got a couple of ways around the problem at the moment
Delete the bin-debug swf
Overwrite it with a release build.
Delete the release swf
Export the release build elsewhere.
Build a debug version again.
This works - sometimes immediately sometimes after a few repetitions.
One other technique I tried today was to change the compiler options to -dump-config=somefile.
This worked immediately, however, I'll need to wait next time to try again.
It might be a situation of changing the -dump-config filename output when this happens.
Just tried another possible fix (which seems to be working really well) - Change the browser that Flex builder is using to a different one. This immediately fixed the problem. I'll post back here later if I find that this is a reliable fix. - Casp