Skip to main content
GameDev.net gamedev.net
🔒 Locked

Class and Thread Problems

Started by Last Attacker Aug 4, 2006 at 5:49 PM 4 replies 650+ views
Original Post
Last Attacker
Last Attacker
Hi everyone! I am writing a ray tracer in C plus plus with wxWidgets and I have a class with 2 virtual functions and 2 classes deriving from that class implementing those virtual functions. The top class is CObject and the lower classes are CSphere and CPlane. Now I wanted to use a thread (maybe 2 later [wink]) to render my scene. I have an array of (CObject *)s which contains CSphere and CPlane objects. When I call the virtual function to execute (you know via polymorphism) from my running thread then the program bombs out with a segmentation fault. I can access the other functions in the CObject class except the virtual functions. I think that threads have a problem with the virtual table or something. I am using the wxThread class for my thread. EDIT: I have done this without threads and it worked 100%, I just want to move over to threads sothat I can implement a progress bar and maybe try to let 2 threads render my scene (maybe it'll be faster, I'll see). Also, I tried this on wxWidgets 2.6.2 & 2.6.3 Anyone know what could be the problem? Thanks [Edited by - Last Attacker on August 5, 2006 2:35:25 AM]
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog
twix
twix
wxWidgets is not thread-safe. If you're making any GUI calls from threads other than the one the wxWidgets event loop is running in, that's likely the reason for the crashes.
Last Attacker
Last Attacker
Well, I'm still busy with my app, so when I click on File->New, it creates a thread, and then is supposed to render my scene. Currently I only have 1 thread doing this.
I'm also not accessing any widgets in my thread, just my arrays and buffers.

I'm using MingW 3.4.4 as my compiler.
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog
Last Attacker
Last Attacker
I saw that even when I remove the 'virtual' keywords and just put CSpheres in the array and cast that object in the array of (CObject *)s to a (CSphere *) and still call that specific funtion, it still bombs out.
So I guess we can scratch out virtual functions to be the problem. Maybe its inherited classes that presents a problem or something.
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog
Last Attacker
Last Attacker
I found out what the problem was!
Thank God that it wasn't a thread problem. I just forgot to dynamically allocate my arrays, etc.
It didn't occur to me that when a thread runs that the local variables are going to "go extinct" while the thread is running so I just "new"ed them all and destroyed them when the thread ended.

Thanks for everyone's replies!
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.