Jump to content

setMemBit error: membit already set


VeTaL
 Share

Recommended Posts

Got this crash while loading objects in the second thread, i got randomly error

"setMemBit error: membit already set"

 

While googling, i found that this error is assigined to Blitz:

 

 

Especially first link solution:

Quote

I figured that much (that it was my wrapper) :-). Anyway, it seems I've fixed my problem. Good to know it has to do with the GC.

 

How can i fix it? Does anybody stuck with this?

Working on LeaFAQ :)

Link to comment
Share on other sites

I ran into that one whilst using a stand alone version of newton set to use two threads. Except that for me, the error was when Newton's callback to set an object's position and rotation, tried to call SetEntityMatrix.

 

My solution was to allow newton to run in two threads to speed up the physics calculation time. But the callback was not allowed to call SetEntityMatrix. Instead I gave each entity a private member for the new matrix and flag to say whether newton had to reposition the entity.

 

Once newton has finished updating, the program is back in a single threaded state, so I can then call SetEntityMatrix one-by-one for each entity that had its move flag set to true. I don't think there is a way to get round loading objects in a second thread though

LE Version: 2.50 (Eventually)

Link to comment
Share on other sites

Ah, so this is caused because of Newton... Thanks, now i have new ideas of solving this problem.

 

No, not Newton, it's a multithreading issue. It's just when I used a standalone newton, the NewtonUpdate() function spawns x threads to do the updating (I had it set to use two threads). Each of the threads calls the same callbacks, at the same time, I had one of the callbacks calling SetEntityMatrix. When I took SetEntityMatrix out of the callback the problem went away because it was no longer being called by two threads at the same time.

 

I could have just told newton to use one thread, but I wanted the physics calculation to be as fast as possible.

 

 

All my Model loading was done single-threaded. So far, the only multi-threaded part of my project is when NewtonUpdate() is called. and the multi-threading ends when that call ends.

LE Version: 2.50 (Eventually)

Link to comment
Share on other sites

//and the multi-threading ends when that call ends.

 

Er... isn't creation/destruction of threads a heavy operation?

 

Damned, i tried to load meshes (without physic), but also caught this crash :(

 

Loading model: 107

Loading model: 108

Loading model: 109

Loading model: 110

Loading model: 111

Loading model: 112

Loading model: 113

Loading model: 114

Loading model: 115

Loading model: 116

Loading model: 117

Loading model: 118

GC bbGCFree: mem has non-0 refs

Working on LeaFAQ :)

Link to comment
Share on other sites

Er... isn't creation/destruction of threads a heavy operation?

 

It might be, but when you have a large number of physics bodies surely having multiple threads will speed up the calculations (But no more threads than you have physical processors). Even when there are only a few physics bodies, using two threads still gets to a nice 60 fps, with enough time to sleep as well.

 

I don't know how Newton handles its threads. All I know is, I type:

 

NewtonSetThreadsCount(NewtonWorld,2);

 

And Newton will use 2 threads each time I update that world. It might create the threads each time I update that world, and destroy them when finished updating. Or it might create the threads up front, and just leave them sleeping when I'm not updating that world.

 

But that's beside the point, most entity commands for Leadwerks do not work in a multithreaded way. You can't even load a sound at the same time you are loading a model. All loading has to be done single threaded.

LE Version: 2.50 (Eventually)

Link to comment
Share on other sites

It is likely you will continue to produce these errors randomly if you try loading objects in a second thread. It isn't designed to do that. I don't know any way around it. BlitzMax's multithreading implementation is not very good due to the garbage collection system.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I find garbage collectors to be a bit overrated anyway. It's like saying: Don't clean your house, anything you've forgotten about will instantly disappear so that the space it occupied is now free for you to fill with something else.

 

Proper use of destructors, as in freeing (or deleting) any allocated memory renders the whole garbage collectors useless. The only time they are acceptable is when memory allocation is hidden from you to try and not complicate the language. If you can allocate "new" objects then really it should be up to you to clean them up.

 

Sadly in this case, the garbage collector is built into the DLL during compilation so you can't remove/disable it.

LE Version: 2.50 (Eventually)

Link to comment
Share on other sites

1) Can i (or, probably you) shut down garbage collector(add a function to do this)? And add mutexes to resource manager.

2) Okay then, can i load assets in the second thread from hard drive to operative memory, and in first thread from memory into engine? Josh, can you add this functionality?

Working on LeaFAQ :)

Link to comment
Share on other sites

GC was a huge mistake to build into BMX, IMO, and there is nothing you can do to get around this. In a simple program GC lets you code without freeing objects. In a complex program, GC is harder to manage then just freeing things yourself. So garbage collection is basically for idiots who can't even write a simple program.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Damned...

 

Josh, but what about second solution in post #11?

I load asset from harddrive to memory in the second thread in engine format, and then i "register" it from the first thread, but this would take some miliseconds (as just copying from memory to memory) and no troubles with GC?

Working on LeaFAQ :)

Link to comment
Share on other sites

Could you not override the MM by keeping a reference to every object in a global vector or list? I'm a C++ newb so I'm not 100% but shouldn't this stop the objects from going out of scope?

 

EDIT: of course it depends what's causing the crash so you'll have to do some investigating.

AMD Phenom 9850 (X4 2.5GHz) | 1066MHz CL5 GEIL Black Dragon (800MHz) | Powercolor ATI 4870 1GB | DFI 790FXB-M2RSH | 24" 1920x1200 | Windows Vista 64-bit Ultimate

Link to comment
Share on other sites

I have some ideas about creating virtual disc and loading assets there in second thread, and then load from virtual disc to Leadwerks, but now sure that it would work and haven't enough time: i may show demo with sawless world this weekend.

 

So i would very appreciate to Josh, if he would write Leadwerks functions for loading from memory, it may takes not more than some hours.

Working on LeaFAQ :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...