Cruisers Forum
 


Join CruisersForum Today

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 30-05-2018, 20:31   #16
Registered User
 
transmitterdan's Avatar

Join Date: Oct 2011
Boat: Valiant 42
Posts: 4,569
Re: Crash when rebuilding texture cache

Quote:
Originally Posted by J805 View Post
With that said, is there something I should do within my install to fix this? Or does this require programming that will be fixed on a future build?


Thanks
Try this:

Close OpenCPN

If using Windows
Delete all files in C:\ProgramData\opencpn\raster_texture_cache

If using Linux
Remove all files in ./OpenCPN/raster_texture_cache

Then restart OpenCPN but don't tell it to rebuild the entire cache. Just let it build as it needs it. When I did that there was no more crashes. If it keeps crashing then turn off texture cache in options and delete all the raster_texture_cache files.
__________________

transmitterdan is online now   Reply With Quote
Old 31-05-2018, 07:19   #17
Registered User
 
boat_alexandra's Avatar

Join Date: Aug 2009
Location: chesapeake bay
Boat: bristol 27
Posts: 3,360
Re: Crash when rebuilding texture cache

Quote:
Originally Posted by transmitterdan View Post
I believe I have narrowed the crash down to a simple double delete of a pointer.

The gltexCache code is loaded with dangling pointers. There are many megabytes left dangling on the heap when the program exits. It needs some serious pointer cleanup.
Can you reproduce it? Which pointer which line of code? How do you know there is so much leaked data? Are you using valgrind?
__________________

boat_alexandra is online now   Reply With Quote
Old 31-05-2018, 08:56   #18
Registered User
 
transmitterdan's Avatar

Join Date: Oct 2011
Boat: Valiant 42
Posts: 4,569
Re: Crash when rebuilding texture cache

I can not reproduce it reliably. I use Visual Studio to catch new/delete faults. I think this is possibly related to some thread safe issue. I will make note of the pointer in question when I get back to my computer.

In my opinion all pointers should be set to NULL after deletion. Visual Studio sets them to 0xcdcdcdcd at deletion and if you try to use (or delete) that pointer later it traps in the debugger. That trap happened on my VS system during the multi threaded cache update process. I believe that is the cause of the non-debug version crash. Deleting a NULL pointer is harmless in C++.

There are many thousands of texture cache objects that are left on the heap when O exits. VS complains about every one, generating hundreds of thousands of dangling pointer warnings. It is truly annoying. An object oriented system like this should delete every object from the heap at shutdown or when the object is no longer needed. There is no shutdown system in the texture cache feature. It makes debugging problems like this very difficult.
transmitterdan is online now   Reply With Quote
Old 31-05-2018, 12:01   #19
Registered User
 
boat_alexandra's Avatar

Join Date: Aug 2009
Location: chesapeake bay
Boat: bristol 27
Posts: 3,360
Re: Crash when rebuilding texture cache

There is a function to free everything that should be called... I haven't looked at the code in a few years.
boat_alexandra is online now   Reply With Quote
Old 31-05-2018, 12:03   #20
Registered User
 
boat_alexandra's Avatar

Join Date: Aug 2009
Location: chesapeake bay
Boat: bristol 27
Posts: 3,360
Re: Crash when rebuilding texture cache

Setting to NULL might fix a crash but doesn't actually find the problem. We shouldn't actually be calling delete more than once on a pointer.

It's possible like you say it is thread issues. Maybe this explains why it crashes only on windows?
boat_alexandra is online now   Reply With Quote
Old 31-05-2018, 19:27   #21
Registered User
 
transmitterdan's Avatar

Join Date: Oct 2011
Boat: Valiant 42
Posts: 4,569
Re: Crash when rebuilding texture cache

Sean,

I made an attempt to fix the one pointer error I found in this branch of my fork.

https://github.com/transmitterdan/Op.../gltexCacheFix
transmitterdan is online now   Reply With Quote
Old 01-06-2018, 01:13   #22
Registered User

Join Date: Jun 2015
Posts: 296
Re: Crash when rebuilding texture cache

Quote:
Originally Posted by transmitterdan View Post
Sean,

I made an attempt to fix the one pointer error I found in this branch of my fork.

https://github.com/transmitterdan/Op.../gltexCacheFix

A smart compiler will remove the m_fs = NULL lines in LoadPath, anyway this patch only make the race window smaller, LoadHeader should not be called from 2 threads without synchronization. So why is it?
did-g is online now   Reply With Quote
Old 01-06-2018, 07:48   #23
Marine Service Provider
 
bdbcat's Avatar

Join Date: Mar 2008
Posts: 5,270
Re: Crash when rebuilding texture cache

did-g...

What part of LoadHeader() is not thread-safe? There is a texture factory class instance per chart. No static storage, AFICT.

Dave
bdbcat is offline   Reply With Quote
Old 01-06-2018, 12:03   #24
Registered User

Join Date: Jun 2015
Posts: 296
Re: Crash when rebuilding texture cache

Quote:
Originally Posted by bdbcat View Post
did-g...

What part of LoadHeader() is not thread-safe? There is a texture factory class instance per chart. No static storage, AFICT.

Dave
I don't know but if transmitterdan patch actually works it only could be a race somewhere:

before in the same function

delete m_fs; // now it's invalid
... some stuff in the same function
all paths end in
m_fs = new ...// now it's valid again


after
delete delete m_fs; // now it's invalid
m_fs = nullptr
... some stuff in the same function



so something in a separate thread was using m_fs and
m_fs = nullptr only reduces the time it is invalid




I made a PR which seems to fix all crashes I could reproduce
https://github.com/OpenCPN/OpenCPN/pull/1084


Anyway with c++11 we can get ride of that kind of hard to get right code soon.
did-g is online now   Reply With Quote
Old 01-06-2018, 14:31   #25
Registered User
 
boat_alexandra's Avatar

Join Date: Aug 2009
Location: chesapeake bay
Boat: bristol 27
Posts: 3,360
Re: Crash when rebuilding texture cache

It's supposed to be protected with mutexes to prevent more than one thread accessing the same data. So the problem is not really to do with delete or setting pointers null.
boat_alexandra is online now   Reply With Quote
Old 01-06-2018, 18:49   #26
Marine Service Provider
 
bdbcat's Avatar

Join Date: Mar 2008
Posts: 5,270
Re: Crash when rebuilding texture cache

did-g...

Except we will not have full c++11 on all required platforms anytime soon. We need to understand this in old-fashioned c++ logic, ugly as it might be...

Dave
bdbcat is offline   Reply With Quote
Old 01-06-2018, 23:22   #27
Registered User
 
transmitterdan's Avatar

Join Date: Oct 2011
Boat: Valiant 42
Posts: 4,569
Re: Crash when rebuilding texture cache

What i saw was the pointer got deleted twice. I don’t see why the compiler would optimize away setting it to NULL. In my view that would be an error because the variable is used in more than one member function.

Also, I found the lat and Lon values sometimes coming up NAN. That is why I added the tests for that. That may have been a byproduct of the pointer issue.

All I know for sure is I quickly could produce a trap when rebuilding the cache using 8 threads. After my changes it never crashed in 10 texture rebuild attempts.

It would be easier to debug this if the Tex factory could release all its heap objects automatically when O shuts down. Then we might have a chance at finding what is really going on. But as it is there are too many dangling objects to do an effective search. Using the VS heap check in debug mode the program takes 15 minutes at shutdown just to report all the undeleted objects left on the heap. But I have a lot of RNC chart files.
transmitterdan is online now   Reply With Quote
Old 02-06-2018, 07:19   #28
Marine Service Provider
 
bdbcat's Avatar

Join Date: Mar 2008
Posts: 5,270
Re: Crash when rebuilding texture cache

tdan...

The VS Debug heap check gives info on the line where dangling objects are first allocated. Please take a look at some of them, and point us to the indicated code line(s). There are probably only one or two spots, repeated a zillion times.

Thanks
Dave
bdbcat is offline   Reply With Quote
Old 02-06-2018, 08:24   #29
Registered User
 
transmitterdan's Avatar

Join Date: Oct 2011
Boat: Valiant 42
Posts: 4,569
Re: Crash when rebuilding texture cache

Dave,

There are about a half dozen places. I am away from computer but will send line #s as soon as I get back to it.
transmitterdan is online now   Reply With Quote
Old 03-06-2018, 05:26   #30
Registered User

Join Date: Jun 2015
Posts: 296
Re: Crash when rebuilding texture cache

Quote:
Originally Posted by bdbcat View Post
did-g...

Except we will not have full c++11 on all required platforms anytime soon. We need to understand this in old-fashioned c++ logic, ugly as it might be...

Dave
Which platforms isn't c++11?
Is current head still compatible with wx2.x ?
__________________

did-g is online now   Reply With Quote
Reply

Tags
rebuild

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Texture Compression with Caching greyed out J805 OpenCPN 10 22-05-2018 02:55
Rebuild Texture Cache causes crash in OpenCPN 4.0 jim326 OpenCPN 12 04-04-2015 05:00
How To Cover up Texture of Fiberglass Jon Neely Construction, Maintenance & Refit 9 15-05-2011 11:45



Copyright 2002- Social Knowledge, LLC All Rights Reserved.

All times are GMT -7. The time now is 11:07.


Google+
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Social Knowledge Networks
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2018, vBulletin Solutions, Inc.

ShowCase vBulletin Plugins by Drive Thru Online, Inc.