when i first heard about multi-threading, i thought it's pretty much complicated, but this code seems really simple, but...kinda bad results =/
#include "DarkGDK.h"
#include <stdio.h>
#include <windows.h>
#include <process.h> // needed for _beginthread()
#include "time.h"
int ID = 1;
bool load = true;
void thread( void * ); // function prototype
void DarkGDK ( void )
{
dbSyncOn();
dbSyncRate ( 0 );
dbSetDisplayModeAntialias ( 640, 480, 32, 200, 200, 200 );
dbRandomize ( (int)time ( NULL ) );
dbAutoCamOff ( );
// Let's now create our second thread and ask it to start
// in the thread() function.
_beginthread( &thread, 1024, (void*)ID++ );
while ( LoopGDK () )
{
dbControlCameraUsingArrowKeys ( 0, 0.5, 0.5 );
dbText ( 0, 0, dbStr ( dbScreenFPS() ) );
dbText ( 0, 20, dbStr ( ID ) );
dbSync();
}
load = false;
return;
}
void thread( void *arg )
{
while ( load )
{
dbLoadObject ( "fsd.x", ID++ ); //error triggers here
dbPositionObject ( ID-1, dbRND ( 300 ) -150, dbRND ( 100 ) -50, dbRND ( 300 ) -150 );
}
_endthread();
}
IMPRESSIVE speed @ loading
but..it crashes after some time (not constant time, sometimes it crashes after 10 seconds and sometime 2 seconds etc)..any ideas about why?
error message:
Windows has triggered a breakpoint in Dark GDK - Game1.exe.
This may be due to a corruption of the heap, which indicates a bug in Dark GDK - Game1.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while Dark GDK - Game1.exe has focus.
The output window may have more diagnostic information.