Skip to main content

Trying to fix bug 641

11 replies [Last post]
dwarfy
Offline
Joined: 2004-12-16
Points: 0

Hello !

I'm trying to fix the bug 641

>GoL3D (Game of Life) demo app (Startmenu->Games->Gol3D)
>pauses the system when loading a pattern. It seems that
>the pattern loading is done using LG3D event thread.
>GoL3D should use different thread for the work.

I attached 2 files as a proposal patch.
see https://lg3d-core.dev.java.net/issues/show_bug.cgi?id=641

One file is the modified gridcomponent and the other is a new class extending thread that loads a grid config file.
So it should work and not stop the system while loading the file as it is a thread appart but It still seems to pause the system during the loading ..
I do not understand why ?

Does anybody have an idea ?
because I'm really a poor java coder ;)

It's not really an urgent bug but ..

Thanks in advance
Mathieu

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dwarfy
Offline
Joined: 2004-12-16
Points: 0

Even when I do

setPriority(Thread.MIN_PRIORITY);

It hangs for sometimes on load.

Should I put the thread in sleep(); during some miliseconds between each line read from the grid config file ?

Damn I'm bad at java.

Mathieu

dwarfy
Offline
Joined: 2004-12-16
Points: 0

I tried with a sleep(3); and that's not much better.

and a yield(); between each line read.
an that's allready better but not ideal.

But I read on many place to not to use yield();

?

Dwarfy

dwarfy
Offline
Joined: 2004-12-16
Points: 0

Well, to be more clear,
here's how look the run function of my GolGridReader thread class.

[code]
public void run() {
setPriority(Thread.MIN_PRIORITY);
//logger.log(Level.INFO,"Running GolGridReader Thread!");
java.net.URL url = getClass().getClassLoader().getResource("org/jdesktop/lg3d/apps/gol3d/configs/" + filename);
//logger.log(Level.WARNING,"filename = " + filename);
//logger.log(Level.WARNING,"PATH: resolved name = " + url);

try {

InputStream is = url.openStream();
in = new BufferedReader(new InputStreamReader(is));
s = in.readLine();
dim = Integer.parseInt(s);
ref.setDim(dim);
ref.setBoolMatrixSize(dim * dim);
itemWidth = GolGroundComponent.groundInnerWidth / dim;
ref.setItemWidth(itemWidth);
ref.setItemInnerWidth(itemWidth * (1.0f - (2.0f * ref.itemBorderRatio)));
ref.setItemBorderWidth(itemWidth * ref.itemBorderRatio);

//logger.log(Level.INFO,"Dim found : " + dim);

//all bits are initialized to false
lineData= new char[dim+1];

for (int x=0;x //+1 because of the \n
s = in.readLine();
for (int y=0;y if (s.toCharArray()[y] == '1') {
B.set(((y * dim) + x));
}
}

//try {
//sleep(3);
yield();
//} catch (InterruptedException e) {
//}

}

ref.build();

//logger.log(Level.INFO,"boolMatrix : " + B);

} catch(IOException Ioe) {
logger.log(Level.SEVERE,"Error opening grid config from : " + filename);
} catch(NumberFormatException Ne) {
logger.log(Level.SEVERE,"Error bad number format in config from : " + filename);
}

}
[/code]

dwarfy
Offline
Joined: 2004-12-16
Points: 0

Well I don't know why it's all green.
But it shouldn't ..

Mathieu

hideya
Offline
Joined: 2003-07-22
Points: 0

Hi dwarfy,

I checked out the code but just looked fine to me...
You shouldn't need to do any of sleep(), yielf() and setPriority()...

hideya

dwarfy
Offline
Joined: 2004-12-16
Points: 0

Hi hideya.

I commited the files.

It seems I can't add comments to an issue in lg3d-core (strangely I can commit attachements)

Here are my permissions in lg3d-core
(https://lg3d-core.dev.java.net/issues/userprefs.cgi?bank=permissions)

* Attach File:
Project issue tracking - Attach File
* Submit:
Project issue tracking - Submit
* Query:
Project issue tracking - Query

?

Mathieu

hideya
Offline
Joined: 2003-07-22
Points: 0

Hi Mathieu,

> It seems I can't add comments to an issue in lg3d-core (strangely I can commit attachements)

It seems that you don't have an Observer role in lg3d-core.
I just granted it to you. Please try again and let me know if you still see issues.

hideya

dwarfy
Offline
Joined: 2004-12-16
Points: 0

Hi !

>Please try again and let me know if you still see issues.

It's ok now, thanks !

Mathieu

hideya
Offline
Joined: 2003-07-22
Points: 0

Hi dwarfy,

> It's ok now, thanks !

You are welcome! By the way, please realize that I put updated comments to Issue 641:

> My bad -- my initial evaluation of the issue was wrong.
>
> > It seems that the pattern loading is done using LG3D event thread.
>
> Actually, what causing the pause is the grid pattern generation by
> GolGridComponent#setGrid(). This method gets rid of all the cells and then
> create and adds cells. The number of cells could be very large. It caused the
> system pause that calling this method using the LG3D event thread. Could you
> try using another thread when performing the setGrid() action and see if it
> fixes the issue?

Sorry for the confusion...

hideya

dwarfy
Offline
Joined: 2004-12-16
Points: 0

Hi hideya !

Sorry but I will be away for a week of so ..
So I'll commit a new fix try when I'll be back ...

Cheers
Mathieu

hideya
Offline
Joined: 2003-07-22
Points: 0

Hi dwarfy,

> Sorry but I will be away for a week of so ..

No problem!

> So I'll commit a new fix try when I'll be back ...

Thanks :) Talk to you later then,

hideya