
81 Cal.Rptr.2d 535 (1998)
69 Cal.App.4th 382
In re James Warner EICHORN on Habeas Corpus.
No. G022777.
Court of Appeal, Fourth District, Division Three.
December 30, 1998.
*536 O`Melveny & Myers, Phillip R. Kaplan, Brett J. Williamson, Todd A. Green, Newport Beach, and Robert G. Loewy, Los Angeles, for Petitioner.
Michael R. Capizzi, District Attorney, Scott G. Scoville, Deputy District Attorney, for Respondent.
CROSBY, J.
James Eichorn was convicted of a misdemeanor violation of a City of Santa Ana ordinance banning sleeping in designated public areas. The appellate department affirmed his conviction and denied his request to transfer the cause. Eichorn thereafter petitioned for writ of habeas corpus in this court. We conclude his conviction must be set aside.

I
James Eichorn was cited for violation of the city's anti-camping ordinance (Santa Ana Mun.Code, ch. 10, art. VIII, § 10-402) on the evening of January 25, 1993.[1] Following a detour to the Supreme Court that established the ordinance was facially constitutional (Tobe v. City of Santa Ana (1995) 9 Cal.4th 1069, 40 Cal.Rptr.2d 402, 892 P.2d 1145), Eichorn's case eventually went to trial.
In a significant pretrial ruling, the court (Judge Brooks) determined Eichorn could not present a necessity defense (see CALJIC No. 4.43) to a jury. Eichorn had offered to prove that on the night of the violation every shelter bed within the city that was available to a homeless single man with no children was occupied, and that he was involuntarily homeless, i.e., he had done everything he could to alleviate his condition. Due to circumstances beyond his control, defendant, a 14-year resident of Santa Ana, had been unable to find work as a manual laborer that paid enough to allow him to find an alternative place to sleep.
The court determined defendant had not made a sufficient showing to allow a jury to consider his necessity defense: "It appears that the defense of necessity is not supported by the offer of proof. The first element wasn't satisfied, in the court's view, no significant, imminent evil for this defendant or any other person."[2] Defendant objected that the *537 court's ruling "not only goes against what we understand to have been the statements and admissions by the People and by [Judge Margines, who had previously handled the case] but undermines the whole reason why we were going forward at trial ... it's clearly eviscerated our entire defense."
In light of Judge Brooks's ruling on the necessity defense, and noting there was no dispute Eichorn was in a sleeping bag in the civic center on the night in question, Eichorn's lawyer agreed to go forward without a jury on the constitutional issue whether the ordinance was unconstitutional as applied to him based on his alleged involuntary homelessness.
Trial commenced without a jury in May 1996. Officer Carol Craig testified defendant was in a sleeping bag on the ground at about 10:30 p.m. outside a county office building in the civic center. He was using his clothes as a pillow. Craig asked (as she always did) why Eichorn wasn't at the National Guard Armory (a homeless shelter several miles away). A bus from the civic center to the armory usually picked up people between 5:00 and 6:00 p.m. According to Craig's police report, defendant replied he had tried "a while back." It was full, so he never returned. The court judicially noticed that the walk between the civic center and the armory was "through very dangerous areas of town." Police photographed and cited Eichorn, then asked him to move on. He complied.
James Meeker, a professor at the University of California, Irvine in the Department of Criminology, Law and Society, testified he had conducted a study on homelessness in January and February 1993. There were more than 3000 homeless individuals in Orange County during this period. Most homeless were longtime residents of Orange County (average 14 years) who had lost jobs and could not afford housing. The County had relatively little affordable housing, and it had been decreasing. Single men had a particularly difficult time because they were less likely to receive the support from family, friends, or governmental agencies. Most were sleeping outdoors because they had no other choice. Homeless individuals were 10 times as likely to be victimized by crime than the average population. Many homeless stayed in urban areas because of proximity to assistance providers (food, clothing and shelter), day jobs (just eight percent were unemployed and not looking for jobs), public facilities (restrooms etc.) and the lack of transportation.
Timothy Shaw was the executive director of the Orange County Homeless Issues Task Force. He pegged the number of homeless in Santa Ana at about 1500 persons in 1993. There were about 118 shelter beds available for single men like Eichorn, most available on a first-come, first-serve basis. In addition, the armory could accomodate 125 persons during the winter (although it frequently exceeded its capacity). As was routine, these shelters were full on the night Eichorn was cited.
Maria Mendoza was the county's homeless coordinator and oversaw use of the armory as a shelter. The armory was available only on cold winter nights. She explained how the bus to the armory would leave from the civic center in the late afternoon. Those on the bus had priority at the armory. Eichorn had spent some 20 nights there in December and January. On January 25, the armory was 13 persons over capacity, which was not uncommon. That the armory would accept excess capacity was not a given. Usually, only those "at risk" (e.g., women and children) would be admitted after the maximum was reached, and generally only when it was raining.
Eichorn, 49 years old, testified he had moved to Costa Mesa in 1972, a few years after his discharge from the Marine Corps. The Vietnam veteran lost his job in a machine shop in 1980, and subsequently ended up without a place to live. He moved to Santa Ana because a friend told him about a job driving an ice cream truck. He sold ice cream for about a year and was able to afford a motel room. When he lost that job, he frequented the casual labor office in Santa Ana until it closed. When he worked and could save enough, he would live in a motel. He also relied on general relief and food stamps. However, general relief was no longer enough to secure affordable housing because most of the less expensive motels *538 had been torn down. If he could not get into a shelter, Eichorn would sleep in the civic center, where he was close to services (including restrooms) and where there was "safety in numbers" (i.e., where it was less likely someone would steal or attack him while he slept). He loved to work and did so every chance he got. He did not like living outside. He had been turned away from the armory in the past and had a "nervous walk" back to the civic center. On January 25, he did not recall whether he had tried to find a spot at a shelter or whether he heard that the shelters were full. He recalled eating around 7:00 p.m. He was in his sleeping bag listening to his radio when Craig arrived around 10:30 p.m. Eichorn's mother and stepfather lived in Long Beach, but staying with them was not an option because he was "an adult responsible for" himself. Defendant denied a problem with alcohol or drugs.
June Marcott, program manager for food stamps and general relief of the County of Orange, testified Eichorn received food stamps on a regular basis from 1989 through 1993, except when he was employed in parts of 1991 and 1992. He was eligible for $307 monthly in general relief if he participated in a work program (working nine days a month) and looked for work (four job applications per day). He last received general relief in November 1990 and was terminated because he did not submit a job search report. He applied for relief in March and June 1992, but was denied.
The court found Eichorn had violated the camping ordinance and was not involuntarily homeless on the night in question, finding he chose not to go to the armory. He also suggested defendant should have sought out familial assistance and should have applied for general relief. The court ordered him to perform 40 hours of community service. By a 2-to-1 margin, the appellate department of the superior court affirmed the conviction without opinion and declined to certify the case to this court for direct review. (Cal. Rules of Court, rule 63.) Eichorn filed this petition for habeas corpus and seeks to set aside his conviction.[3]

II
Eichorn makes a multipronged attack on his conviction. One of his contentions is that he was induced to waive his right to a jury trial by the court's pretrial ruling that he could not present a necessity defense. As noted above, the court ruled the defense's offer of proof was inadequate, i.e., defendant had not presented enough evidence to get to a jury on the issue of whether he violated the law to prevent a significant evil. This ruling was error, and we vacate the judgment accordingly.
California appellate courts have recognized the necessity defense "despite the absence of any statutory articulation of this defense and rulings from the California Supreme Court that the common law is not a part of the criminal law in California." (People v. Garziano (1991) 230 Cal.App.3d 241, 242, 281 Cal.Rptr. 307.)
*539 In Tobe v. City of Santa Ana, supra, 9 Cal.4th at p. 1088, 40 Cal.Rptr.2d 402, 892 P.2d 1145, the Supreme Court, while holding the camping ordinance was facially valid, declined to decide whether and how it might be unconstitutionally applied. The court refused to assume that the ordinance would be enforced "against persons who have no alternative to `camping" or placing camp paraphernalia' on public property." (Id. at p. 1088, fn. 8, 40 Cal.Rptr.2d 402, 892 P.2d 1145.) Indeed, the Tobe court was given assurances by the People "that a necessity defense might be available to `truly homeless' persons and that prosecutorial discretion would be exercised." (Ibid.)
As the prosecutor recognized at one of the hearings held before trial, "because [defendant has] that necessity defense at trial, [the law] is never applied unconstitutionally. Because of the nature of that defense that we're incorporating into our definition, there will never be an unconstitutional application." The court (Judge Margines) reasoned similarly: "I think ... the statute will not be applied unconstitutionally to these people; because if they are truly in the class that [defense counsel says] renders the application unconstitutional, then they will be found not guilty by virtue of the necessity defense. [The defense has] the burden of demonstrating that they fall within the class. It's the same burden you have at trial if you present a necessity defense."
An instruction on the defense of necessity is required where there is evidence "sufficient to establish that defendant violated the law (1) to prevent a significant evil, (2) with no adequate alternative, (3) without creating a greater danger than the one avoided, (4) with a good faith belief in the necessity, (5) with such belief being objectively reasonable, and (6) under circumstances in which he did not substantially contribute to the emergency. [Citations.]" (People v. Pepper (1996) 41 Cal.App.4th 1029, 1035, 48 Cal. Rptr.2d 877; People v. Pena (1983) 197 Cal. Rptr. 264, 149 Cal.App.3d Supp. 14.)
The defense of necessity is "founded upon public policy and provides a justification distinct from the elements required to prove the crime. [Citation.] The situation presented to the defendant must be of an emergency nature, threatening physical harm, and lacking an alternative, legal course of action. [Citation.] The defense involves a determination that the harm or evil sought to be avoided by such conduct is greater than that sought to be prevented by the law defining the offense charged. [Citation.] Necessity does not negate any element of the crime, but represents a public policy decision not to punish such an individual despite proof of the crime, [¶] An important factor of the necessity defense involves the balancing of the harm to be avoided as opposed to the costs of the criminal conduct. [Citation.] Unlike duress, the threatened harm is in the immediate future, which contemplates the defendant having time to balance alternative courses of conduct. [Citation.] The defendant has the time, however limited, to form the general intent required for the crime, although under some outside pressure. [Citation.] Thus, the defense does not negate the intent element, and the defendant has the burden of proving the defense by a preponderance of the evidence." (People v. Heath (1989) 207 Cal.App.3d 892, 901, 255 Cal.Rptr. 120.) Whether necessity exists is generally a question of fact. (See People v. Lovercamp (1974) 43 Cal.App.3d 823, 832, 118 Cal.Rptr. 110.)
At a minimum, reasonable minds could differ whether defendant acted to prevent a "significant evil." Sleep is a physiological need, not an option for humans. It is common knowledge that loss of sleep produces a host of physical and mental problems (mood irritability, energy drain and low motivation, slow reaction time, inability to concentrate and process information). Certainly, no one would suggest that a groggy truck driver who stops his rig on the side of a road rather than risk falling asleep at the wheel does not act to prevent a significant evil, i.e., harm to himself and others. Indeed, Judge Margines had denied Eichorn's request for funds to hire an expert to testify about the harmful effects of sleep loss: "I mean it doesn't take an expert to tell us that, to convince a person, that there are ill effects that arise from sleep [deprivation]."
*540 The court must instruct if the evidence could result in a finding defendant's criminal act was justified by necessity. (People v. Slack (1989) 210 Cal.App.3d 937, 941, 258 Cal.Rptr. 702.) Eichorn's offer of proof was sufficient. There was substantial if not uncontradicted evidence that defendant slept in the civic center because his alternatives were inadequate[4] and economic forces were primarily to blame for his predicament. Thus, whether denominated a denial of his right to jury trial[5] or of his due process right to present a defense (see People v. Schroeder (1991) 227 Cal.App.3d 784, 787, 278 Cal.Rptr. 237 [noting the "right of a criminal defendant to present a defense and witnesses on his or her behalf is a fundamental element of due process guaranteed under the Fourteenth Amendment to the United States Constitution"] ), the court's error was clear, fundamental, and struck at the heart of the trial process.
Finally, because Eichorn is entitled to raise a necessity defense to charges he violated the camping ordinance, we find no other constitutional violations under the circumstances of this case. (See Robinson v. California (1962) 370 U.S. 660, 82 S.Ct. 1417, 8 L.Ed.2d 758 [state law making status of narcotic addiction a criminal offense inflicted cruel and unusual punishment in violation of the Fourteenth Amendment].)
The writ is granted and the cause remanded to the former municipal court with directions to set aside the judgment of conviction and to proceed in conformity with this opinion.
SILLS, P.J., and WALLIN, J., concur.
NOTES
[1]  Section 10-402 reads as follows: "Unlawful Camping. [¶] It shall be unlawful for any person to camp, occupy camp facilities or use camp paraphernalia in the following areas, except as otherwise provided: [¶] (a) any street; [¶] (b) any public parking lot or public area, improved or unimproved." Camp paraphernalia included a sleeping bag.
[2]  The court's questions and comments suggested it was not impressed with defendant's claim lack of sleep was a significant evil ("what do you mean `bodily harm?' Like tired eyelids or blood?"; [I]f he didn't sleep here, he'd lose sleep and this would be a horrible physical thing to impose on him?").
[3]  The district attorney raises a preliminary procedural bar to the petition because Eichorn (unsuccessfully) raised the same issues in the appellate department in his direct appeal. (In re Harris (1993) 5 Cal.4th 813, 825, 21 Cal.Rptr.2d 373, 855 P.2d 391 ["[h]abeas corpus will not serve as a second appeal"].) Harris noted "that in the absence of strong justification, any issue that was actually raised and rejected on appeal cannot be renewed in a petition for a writ of habeas corpus." (Id. at p. 829, 21 Cal.Rptr.2d 373, 855 P.2d 391.)

Eichorn fits within an exception because, as we discuss below, the trial court misapplied the law and no material facts are in dispute. (See In re Wallace (1970) 3 Cal.3d 289, 293, 90 Cal.Rptr. 176, 475 P.2d 208 [court entertained habeas corpus petition after denial of certification where petition involved issues already litigated and it appeared "the statute under which [the defendant] was convicted did not prohibit his conduct"]; In re Catalano (1981) 29 Cal.3d 1, 7, fn. 7, 171 Cal.Rptr. 667, 623 P.2d 228 [even untimely request for decertification does not bar relief].) There is no meaningful dispute about the underlying facts; only their legal significance is at issue. We also agree with Eichorn that his petition raises several issues that implicate clear and fundamental rights bearing on the issue of his guilt. (In re Harris, supra, 5 Cal.4th at p. 830, 21 Cal.Rptr.2d 373, 855 P.2d 391 ["`If the violation of a petitioner's constitutional rights ... had any bearing on the issue of his guilt, there should be no doubt that habeas corpus would be available.'"].)
[4]  In connection with its pretrial ruling that defendant could not present a necessity defense, the court suggested defendant had adequate alternatives to sleeping in a public place in Santa Ana ("The court is aware, firsthand [that] other buildings, nearby churches [etc.] ... have rear stairs, rear doors....; Couldn't your client have found a nice little warm, covered stairwell, on private property, to sleep?"; "[H]ow about [other] private property, backyards, trees, under a tree in a condemned home?"; is [it] a reasonable alternative... walking a mile or so [to a nearby city without a camping ordinance?] Stroll on a nice sunny day, find a cushy spot in Tustin, in a city park and make his home there.") For guidance of the court at any retrial, neither trespassing on private property nor walking to a different city was an adequate alternative. Simply put, Santa Ana may not "solve" its social problems by foisting them onto nearby localities; an individual who has no reasonable alternative to sleeping in a public place in Santa Ana need not travel in search of streets and other public places where he can catch his 40 winks.
[5]  Of course, the right to trial by jury embodied in the California Constitution extends to so-called "petty" as well as to "serious" criminal offenses, i.e., to misdemeanors as well as felonies. (Mitchell v. Superior Court (1989) 49 Cal.3d 1230, 1242, 265 Cal.Rptr. 144, 783 P.2d 731.) Defendant cites People v. Sandoval (1987) 188 Cal.App.3d 1428, 1435, 234 Cal.Rptr. 97, where the court addressed a claim that a jury trial waiver was constitutionally flawed because it was based on the court's evidentiary error. In Sandoval the trial court erred when it failed to exercise discretion under Evidence Code section 352 concerning impeaching defendant with prior convictions. As a result of this erroneous pretrial ruling, defendant waived a jury, believing he could not get a fair trial if the jury learned of his priors. The court observed that "One's choice to forgo a jury trial should not be forced by a concern that to do so provides the only fundamentally `fair' trial opportunity that the determined a waiver under these circumstances. Certainly, there is no incentive for the People or the court to exercise discretion in evaluating admission of prior conviction evidence, if a blanket admission policy would ease their procedural burden by coercing waivers of jury trials constituted so as to deny fundamental constitutional rights." (Id. at p. 1434, 234 Cal.Rptr. 97.) However, Sandoval held the error was subject to the Watson test for reversible error: "To apply a reversal per se rule in a case where a fully informed defendant waives a jury trial merely to avoid adverse pretrial evidentiary rulings which later prove erroneous would permit litigants to abuse the judicial process. Defendants caught red-handed, facing insurmountable proof, would be encouraged to inundate the courts with in limine evidentiary motions, hoping to obtain one which is erroneous, regardless of its significance to establishment of guilt. To require reversal of a fundamentally fair court trial merely because a defendant couples his jury waiver with a statement that it was to avoid the impact of evidence later held inadmissible, without regard to its effect on the judgment, does not promote respect for the judicial system." (Id. at p. 1436, 234 Cal.Rptr. 97.) To the extent Sandoval is on point, it is distinguishable in that Eichorn's court trial was not "fundamentally fair" because he was deprived of his only defense to the charge.
