POV-Ray : Newsgroups : povray.windows : Calling Povray from an other program Server Time
23 Nov 2024 22:51:49 EST (-0500)
  Calling Povray from an other program (Message 1 to 3 of 3)  
From: wkx
Subject: Calling Povray from an other program
Date: 8 Aug 2002 10:45:05
Message: <web.3d528293c353cbdab4b13400@news.povray.org>
Hi all
I write a small app in VC which uses POV-Ray for Window to render some
bitmaps. Then I postprocess the Bitmaps created by POV-Ray so it is
important to wait until the rendering is complete. I achieve this by
synchronizing with POV-Ray which works fine, but it is very annoying that
you have to close all POV-Ray windows manually.

In a batch-file it worked with the parameter "/EXIT" but in my app this
parameter seems to have no effect (POV-Ray does not close when the render
is complete).

Here is a piece of code:

HANDLE hProcess;
PROCESS_INFORMATION ProcessInfo;
STARTUPINFO StartupInfo;
CString sParams;
sParams.Format("/EXIT /NR +I%s +w%d +h%d +kfi0 +kff%d -p -a", sFileName,
nSize, nSize, m_nStates-1);
FillMemory(&StartupInfo, sizeof(STARTUPINFO), 0);
StartupInfo.cb = sizeof(STARTUPINFO);
CString strPovray = m_pProperties->m_path.m_strPovray;
::CreateProcess(strPovray, strParams, NULL, NULL, true, 0, NULL, NULL,
&StartupInfo, &ProcessInfo);
hProcess = ::OpenProcess(SYNCHRONIZE | PROCESS_TERMINATE, false,
ProcessInfo.dwProcessId);
if (::WaitForSingleObject(hProcess, 30000) == WAIT_TIMEOUT) {
  ::TerminateProcess(hProcess, 0);
}
::CloseHandle(hProcess);

Anyone?
Thanks


Post a reply to this message

From: Philippe Lhoste
Subject: Re: Calling Povray from an other program
Date: 8 Aug 2002 11:11:08
Message: <Xns9264AEAAD8065PhiLho@204.213.191.226>
"wkx" <nomail@nomail> wrote in 
news:web.3d528293c353cbdab4b13400@news.povray.org:

> Hi all
> I write a small app in VC which uses POV-Ray for Window to render some
> bitmaps. Then I postprocess the Bitmaps created by POV-Ray so it is
> important to wait until the rendering is complete. I achieve this by
> synchronizing with POV-Ray which works fine, but it is very annoying
> that you have to close all POV-Ray windows manually.
> 
> In a batch-file it worked with the parameter "/EXIT" but in my app
> this parameter seems to have no effect (POV-Ray does not close when
> the render is complete).
> 
> Here is a piece of code:
> 
> HANDLE hProcess;
> PROCESS_INFORMATION ProcessInfo;
> STARTUPINFO StartupInfo;
> CString sParams;
> sParams.Format("/EXIT /NR +I%s +w%d +h%d +kfi0 +kff%d -p -a", sFileName,
> nSize, nSize, m_nStates-1);
> FillMemory(&StartupInfo, sizeof(STARTUPINFO), 0);
> StartupInfo.cb = sizeof(STARTUPINFO);
> CString strPovray = m_pProperties->m_path.m_strPovray;
>::CreateProcess(strPovray, strParams, NULL, NULL, true, 0, NULL, NULL,
> &StartupInfo, &ProcessInfo);

You should check the result of CreateProcess... Why are you setting the 
bInheritHandles parameter to true? It is traditionally set to FALSE, 
unless really needed.

> hProcess = ::OpenProcess(SYNCHRONIZE | PROCESS_TERMINATE, false,
> ProcessInfo.dwProcessId);

No need for this call, you can use ProcessInfo.hProcess.

> if (::WaitForSingleObject(hProcess, 30000) == WAIT_TIMEOUT) {
>  ::TerminateProcess(hProcess, 0);
> }

Mmm, using TerminateProcess is very bad, it kills the process without 
closing DLLs, releasing memory, etc. It really should be used only in 
extreme cases, like debugging. 30s is quite short for a POV-Ray rendering, 
but now I don't know your scenes.

>::CloseHandle(hProcess);

::CloseHandle(ProcessInfo.hThread);
::CloseHandle(ProcessInfo.hProcess);

Seems cleaner... At least, that's what Microsoft says...

Now, I didn't answered your question... :-(
I have a meeting, I will look closer after.

Regards.

-- 
--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
http://jove.prohosting.com/~philho/


Post a reply to this message

From: wkx
Subject: Re: Calling Povray from an other program
Date: 9 Aug 2002 06:05:05
Message: <web.3d5392ba2bbafd35f64027c00@news.povray.org>
Thank you for your reply!

>You should check the result of CreateProcess... Why are you setting the
>bInheritHandles parameter to true? It is traditionally set to FALSE,
>unless really needed.

I do check the result, I just shortened the code a bit to be more readable
:-)

>> hProcess = ::OpenProcess(SYNCHRONIZE | PROCESS_TERMINATE, false,
>> ProcessInfo.dwProcessId);
>
>No need for this call, you can use ProcessInfo.hProcess.

Are you sure? I think I've tried it but WaitForSingleObject returned
immediately. Perhaps this is OS-specific (I use Win2000). The docs state
that the SYNCHRONIZE flag is only available in NT/2000 ... After doing
another test it worked without OpenProcess(), however, this time I called
MS-DOS Povray.

>> if (::WaitForSingleObject(hProcess, 30000) == WAIT_TIMEOUT) {
>>  ::TerminateProcess(hProcess, 0);
>> }
>
>Mmm, using TerminateProcess is very bad, it kills the process without
>closing DLLs, releasing memory, etc. It really should be used only in
>extreme cases, like debugging. 30s is quite short for a POV-Ray rendering,
>but now I don't know your scenes.

You're right. The TerminateProcess thing was a quick & dirty workaround to
force POV-Ray to close, I deleted it. And these 30 seconds are enough for
my needs. The problem is that I render dozens of symbol-sized images which
render very fast- and then it is really a problem if my app expects the
user to close POV-Ray manually.
>>::CloseHandle(hProcess);
>
>::CloseHandle(ProcessInfo.hThread);
>::CloseHandle(ProcessInfo.hProcess);
>
>Seems cleaner... At least, that's what Microsoft says...

Ok

>Now, I didn't answered your question... :-(
>I have a meeting, I will look closer after.

I switched to the previous MS-Dos version, which suits my needs. It's
just a pity that I can't use all the cool new features of v3.5 :-(

Thanks anyway
Ludwig


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.