POV-Ray : Newsgroups : povray.general : possible #switch error : Re: possible #switch error Server Time
30 Jul 2024 04:24:03 EDT (-0400)
  Re: possible #switch error  
From: Alain
Date: 11 Nov 2009 17:23:19
Message: <4afb3957$1@news.povray.org>
Chris B a écrit :
> 
> "Brickman Brick" <ano### [at] anonymousorg> wrote in message 
> news:4afab1ab@news.povray.org...
>> Hello,
>>
>> I stumbled on some possible strange behaviour in the switch statement. I
>> just want to verify if I am doing something wrong or POV-Ray.
>>
> 
> Hi.
> I use and abuse the switch statement quite a lot and I've not found any 
> problems with it, so I suspect that you're doing something wrong, though 
> you haven't provided enough info to really be sure of that.
> 
> 
>> The switch statement is placed inside a loop to calculate a value of a
>> variable many times.
>>
>> Here is a short example of the code I wrote. I omitted the necessary
>> #break statements for readability.
>>
>> #switch (MySwitchValue)
>> #case (1) //do something
>> #case (2) //do something else
>> #case (3) //etc1
>> #case (0) //etc2
>> #else
>> #end
>>
>> Now this code works perfectly fine most of the time. Only sometimes it
>> breaks and it seems that a #case (1) statement is just partly executed.
>> After that, it continues just as expected.
> 
> My first suspect would be the calculated variable. Are you sure it 
> definitely results in an integer value that will match one of the #case 
> statements? If it's actually a decimal value then it may be slipping 
> through to the #else statement. Beware that it's easy to fool yourself 
> into thinking that you're getting an integer value by using #debug 
> str(MySwitchValue,1,3) which will round the value to 3 decimals, which 
> is not necessarily close enough to trip the #case statement.
> 
> Otherwise I think you'll need to find out the exact circumstances that 
> causes it to break (using strategically placed debug statements), or at 
> least provide a cut-down, but complete example that would enable someone 
> else to replicate the problem. If it only fails 1 in 1000 times then 
> provide an example with a loop that's large enough to consistently fail.
> 
> 
>> Now when I do the following the code works again as expected.
>>
>> #switch (MySwitchValue)
>> #debug "MyMessage"
>> #case (1) //do something
>> #case (2) //do something else
>> #case (3) //etc1
>> #case (0) //etc2
>> #else
>> #end
>>
>> Moving the #case (0) right in front of #case (1) also works.
>> This case gives me the impression that the order seems important. On the
>> other hand the example with the #debug statement indicates the opposite.
>> Also, the docs say I may put the clauses in any order I want.
>>
> 
> This sounds quite odd. When you have explored all other possible causes. 
> it may be worth considering that the file or that your installation may 
> be corrupt in some way. I have occasionally had wierd things happen 
> where simply deleting and manually rekeying lines have cured the 
> problem. I've rationalised this by believing that I may have 
> accidentally typed an invisible hex character into the file that's 
> corrupted it, or that it's somehow been corrupted by a disk read or 
> write error. If you think the application may have gotten corrupted, 
> then you may want to consider reinstalling it. I'd wait for a bit before 
> exploring these more radical ideas though as someone else might come up 
> with other ideas.
> 
> Regards,
> Chris B.
> 

You are much more likely to have a silent data corruption during a disk 
write or read than to accidently imput a non-printable character.

A thing that often work if you do have non-printable character(s) 
causing you problems in a scene file, is to sellect all (Ctrl+A), hit 
Ctrl+C or Ctrl+X, then Ctrl+V, then save the file.
Normaly, the non-printable characters are NOT copied to the clipboard.


Alain


Post a reply to this message

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